I have in my root web folder public_html/ installed my info webpage using rewrite rules (seo). In subfolder public_html/shop/ I have installed Opencart so the access to cart is http://www.mydomain.com/shop/. Each folder public_html, public_html_shop/ has own .htaccess file.
I would like to use OC1551 as multistore on several domains redirected to this folder, but also as www.mydomaincom/shop/ - not redirected: www.mydomain1.com, www.mydomain2.com and also as www.mydomain.com/shop/
*public_html/shop/.htaccess* file need to set rewritebase as /shop/ for properly working with info webpage, because use rewriting rules for www.mydomain.com/, but for www.mydoaminX.com need to be set as rewritebase / .
Can you pls someone help me with setting rewritebase in these folders to work it right? Something like dynamicaly changing rewritebase in public_html/shop/.htaccess file.
Thanks
file public_html/.htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^.*$ http://www.mydomain.sk/$0 [NC,L,R=301]
RewriteRule ^(.*)/(.*)-([1-9])/(.*)/$ /index.php?category=$1&page=$2&gallery_page=$3&photo=$4 [L,QSA]
RewriteRule ^(.*)/(.*)/(.*)/$ /index.php?category=$1&page=$2&photo=$3 [L,QSA]
RewriteRule ^(.*)/(.*)-([1-9])/$ /index.php?category=$1&page=$2&gallery_page=$3 [L,QSA]
RewriteRule ^(.*)/(.*)/$ /index.php?category=$1&page=$2 [L,QSA]
RewriteRule ^(.*)/$ /index.php?category=$1 [L,QSA]
Rewriterule ^subscribe.php(.*)$ /index.php?category=overenie&addr=$1 [L,QSA]
Rewriterule ^sitemap.xml$ /webmap.php?engine=google [L,QSA]
Rewriterule ^urllist.txt$ /webmap.php?engine=yahoo [L,QSA]
file public_html/shop/.htaccess
RewriteEngine On
RewriteBase /shop/
RewriteCond %{HTTP_HOST} ^maydomain1\.com$ [NC]
RewriteRule ^.*$ http://www.mydomain1.com/$0 [NC,L,R=301]
RewriteCond %{HTTP_HOST} ^mydomain2\.com$ [NC]
RewriteRule ^.*$ http://www.mydomain2.com/$0 [NC,L,R=301]
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
I actually find on the majority of servers that you can just remove the RewriteBase completely and it's smart enough to work out what it is. I would recommend trying this and seeing if it works
Related
I am currently using htaccess to force to use index.php file. like given below.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [L]
In current website it has some uploaded contents like
uploads/item/11.jpg
uploads/item/12.jpg
uploads/item/13.jpg
I wanted to re re-write it like.
uploads/item/11.jpg => uploads/item/11-itemName11whatEver.jpg
uploads/item/12.jpg => uploads/item/12-itemName12whatEver.jpg
uploads/item/13.jpg => uploads/item/13-itemName13whatEver.jpg
Can anyone help me to find RewriteCond and RewriteRule for this.
Updated
Updated htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} uploads-
RewriteRule ^uploads-([^/]+)-([0-9]+)-[^.]+\.([a-z]+)$ uploads/$1/$2.$3 [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [L]
This helps me to make the URL look like
www.store45.loc/uploads-item-11-sample-watch.jpg
RewriteCond %{REQUEST_FILENAME} uploads-
RewriteRule ^uploads-([^/]+)-([0-9]+)-[^.]+\.([a-z]+)$ uploads/$1/$2.$3 [L,NC]
I am new to this.
Code from my .htaccess file goes like this:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^(.*) http://%1/$1 [R=301,NE,L]
Redirect 301 /abc/ /abcnew/
I want this to redirect from www to non-www i.e., from http://www.example.com to http://example.com
I copied:
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^(.*) http://%1/$1 [R=301,NE,L]
this code from here Generic htaccess redirect www to non-www.
I also checked in /etc/apache2/mods-enabled folder on my linux server. There "rewrite.load" this module is present.(I think this might mean that rewrite is enabled on my server, but correct me if I am wrong.)
Redirect 301 /abc/ /abcnew/
and just FYI this above code works fine(its redirecting my old links to new links).
I also tried this.
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
Doesn't work for me.
Please help. Thanks in advance...
Edit:
this link I found this. But not sure what should be edited. Can anyone please point out.?
You need to place external (full) redirect rules before internal rewrite ones and also make sure to use mod_rewrite rules only.
Try this:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^(.*) http://%1/$1 [R=301,NE,L]
RewriteRule ^abc/?$ /abcnew/ [L,NC,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
So My problem is that when visiting example.com/members I am redirected to www.example.commembers/ (notice that this is not a valid web address) instead of members.example.com (It only works correctly when there is the www). However, this redirection seems to happen with or without the following htaccess file. What to I need to add/change to stop this problem.
This is my htaccess file located in the members folder:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
RedirectMatch 301 ^/members/(.*)$ http://members.example.com/$1
Then there is the wordpress htaccess file in the root directory:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Problem is in your first rule. Change your code to:
RewriteEngine On
RewriteBase /members/
RewriteCond %{HTTP_HOST} !^members\. [NC]
RewriteRule ^(.*)$ http://members.example.com/$1 [L,R=301,NC]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
I have an old website i'm trying to take over, and it has a bad htaccess file here that I need to adjust to enable 'FOLDERS', instead of routing EVERYTHING.
So I have a folder called, "RESOURCES", but it's trying to route through the index file with it..... but I need to load the resource folder instead of routing. How do I make an exception?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.website\.ca$ [NC]
RewriteRule .? http://www.website.ca%{REQUEST_URI} [R=301,L,QSA]
RewriteRule ^(browse)/?$ /browse.php [L,QSA]
RewriteRule ^([\ \+\-0-9a-zA-Z_]+)/?$ /index.php?where=$1 [L,QSA]
#RewriteRule ^([\ \+\-0-9a-zA-Z_]+)/([-0-9a-zA-Z_]+)/([-0-9a-zA-Z_]+)/?$ /index.php?where=$1&what=$2 [L,QSA]
RewriteRule ^(-0-9a-zA-Z_]+)/([-0-9a-zA-Z_]+)/?$ /index.php?where=$1&what=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . / [R=301,L,QSA]
</IfModule>
Add this rule just below RewriteBase /
RewriteRule ^RESOURCES/- [L,NC]
This will skip rest of the rewrite rules for folder called RESOURCES
To skip all the folders use this rule:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^- [L]
My .htaccess in a folder looks like:
RewriteEngine On
RewriteBase /profile/
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?username=$1
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/profile/$1 [R=301,L]
Basically, if you go to www.mySite.com/profile/Username, my index.php file takes 'Username' as a $_GET variable, and the URL will look clean (www.mySite.com/profile/Username)
However if you go to mySite.com/profile/username (omitting the www), the URL will look like http://www.mySite.com/profile/index.php?username=username
How can I make it so only the www is added without messing the URL up?
Thanks
Ordering of rules does matter in .htaccess.
Try this code instead:
RewriteEngine On
RewriteBase /profile/
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/profile/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ index.php?username=$1 [L,QSA]