I have an .htaccess that is working fine, I just need to add the page name before the parameters
Options -MultiViews
RewriteEngine On
RewriteBase /new/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
# PRODUCT PAGE IS WORKING GREAT
# NEWS PAGE I AM TRYING TO SHOW THE PAGE NAME
RewriteCond %{THE_REQUEST} /morenews\?id=([^&\s]+)\s [NC]
RewriteRule . morenews/%1/? [R=301,L]
RewriteRule ^morenews/([^/]+)/$ morenews?id=$1 [L]
# THIS ISLEADING TO INTERNATL SERVER ERROR 500
#http://www.lebmotors.com/new/morenews/12/
# PRODUCT PAGE IS WORKING GREAT
# NEED TO SHOW moreprod before parametsr it is now just website new/1/2/3/4 i ned to make it website/new/moreprod/2/2/3/4
RewriteCond %{THE_REQUEST} /moreprod\?id=([^&\s]+)\s [NC]
RewriteRule . %1/? [R=301,L]
RewriteCond %{THE_REQUEST} /moreprod\?id=([^&\s]+)&topid=([^&\s]+)\s [NC]
RewriteRule . %1/%2/? [R=301,L]
RewriteCond %{THE_REQUEST} /moreprod\?id=([^&\s]+)&topid=([^&\s]+)&catid=([^&\s]+)\s [NC]
RewriteRule . %1/%2/%3/? [R=301,L]
RewriteCond %{THE_REQUEST} /moreprod\?id=([^&\s]+)&topid=([^&\s]+)&catid=([^&\s]+)&cagid=([^&\s]+)\s [NC]
RewriteRule . %1/%2/%3/%4/? [R=301,L]
RewriteRule ^([^/]+)/$ moreprod?id=$1 [L]
RewriteRule ^([^/]+)/([^/]+)/$ moreprod?id=$1&topid=$2 [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ moreprod?id=$1&topid=$2&catid=$3 [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ moreprod?id=$1&topid=$2&catid=$3&cagid=$4 [L]
I am trying to show pagename before paramters
Resolved, just moved these lines to the bottom of .htaccess
RewriteEngine On
RewriteBase /new/
....
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/? [R=301,L]
.....
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)&topid=([^&\s]+)&catid=([^&\s]+)&cagid=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/%2/%3/%4/? [R=301,L]
RewriteRule ^moreprod/([^/]+)/$ moreprod.php?id=$1 [L]
.....
RewriteRule ^moreprod/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ moreprod.php?id=$1&topid=$2&catid=$3&cagid=$4 [L]
# THIS TO THE BOTTOM
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
Related
I use this htaccess for multiple parameters like bank, state,district & branch.
But it only format bank not others...???
I need it for:
www.domain.com/bank/ .....(It works)
www.domain.com/bank/state/
www.domain.com/bank/state/district/
www.domain.com/bank/state/district/branch/
My htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /index\.php\?bank=([^&\s]+)
RewriteRule ^ /%2/? [L,R=301]
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /index\.php\?bank= ([^&]+)&state=([^&]+)
RewriteRule ^ /%2/%3/? [L,R=301]
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /index\.php\?bank=([^&]+)&state=([^&]+)&district=([^&]+)
RewriteRule ^ /%2/%3/%4/? [L,R=301]
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /index\.php\?bank=([^&]+)&state=([^&]+)&district=([^&]+)&branch=([^&]+)
RewriteRule ^ /%2/%3/%4/%5/? [L,R=301]
# Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\.(.*)
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
Kindly provide solution for this...Thanks & Regards.
You need to tweak your regex and reverse order of redirect rules:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /index\.php\?bank=([^&\s]+)&state=([^&\s]+)&district=([^&\s]+)&branch=([^&\s]+)\s
RewriteRule ^ /%2/%3/%4/%5/? [L,R=301]
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /index\.php\?bank=([^&\s]+)&state=([^&\s]+)&district=([^&\s]+)\s
RewriteRule ^ /%2/%3/%4/? [L,R=301]
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /index\.php\?bank= ([^&\s]+)&state=([^&\s]+)\s
RewriteRule ^ /%2/%3/? [L,R=301]
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /index\.php\?bank=([^&\s]+)\s
RewriteRule ^ /%2/? [L,R=301]
# Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\.(.+)$
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
Make sure to clear your browser cache before testing this change.
this is not working, which is supposed to be the easy part
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
RewriteCond %{THE_REQUEST} /rent\.php
#RewriteRule . RentCar/ [R=301,L]
RewriteRule ^RentCar/$ rent.php[L]
RewriteCond %{THE_REQUEST} /rent
RewriteRule ^RentCar/$ rent[L]
While more compliacted parts which are BEFORE this code work
RewriteCond %{THE_REQUEST} /rent2\.php\?r=([^&\s]+)\s [NC]
RewriteRule . CarRental/%1/? [R=301,L]
RewriteCond %{THE_REQUEST} /rent2\.php\?r=([^&\s]+)&w=([^&\s]+)\s [NC]
RewriteRule . CarRental/%1/%2/? [R=301,L]
RewriteRule ^CarRental/([^/]+)/$ rent2.php?r=$1 [L]
RewriteRule ^CarRental/([^/]+)/([^/]+)/$ rent2.php?r=$1&w=$2 [L]
It was resolved after some focus:
RewriteCond %{THE_REQUEST} /rent.php\s [NC]
RewriteRule . RentACar/ [R=301,L]
RewriteRule ^RentACar/$ rent.php [L]
Now Working
http://www.lebmotors.com/new/RentACar/
I provided this .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.lebmotors.com/new/
RewriteRule (.*) http://www.lebmotors.com/new/$1 [R=301,L]
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ moreprod.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ moreprod.php?id=$1
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ moreprod.php?id=$1&topid=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ moreprod.php?id=$1&topid=$2
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ moreprod.php?id=$1&topid=$2&catid=$3
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ moreprod.php?id=$1&topid=$2&catid=$3
Still it does not work
I get: http://www.lebmotors.com/new/moreprod.php?id=107&topid=4&catid=8
What AM I doing wrong
Many Thanks
First of all, you don't need to repeat RewriteEngine On directive.
Then, when you add your rules, you still can access your pages via moreprod.php (but you can also access it from new clean url).
Here's how your htaccess should look like, assuming moreprod.php is also in new folder
Options -MultiViews
RewriteEngine On
RewriteBase /new/
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/? [R=301,L]
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)&topid=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/%2/? [R=301,L]
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)&topid=([^&\s]+)&catid=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/%2/%3/? [R=301,L]
RewriteCond %{THE_REQUEST} /morenews\.php\?id=([^&\s]+)\s [NC]
RewriteRule . morenews/%1/? [R=301,L]
RewriteRule ^morenews/([^/]+)/$ morenews.php?id=$1 [L]
RewriteRule ^moreprod/([^/]+)/$ moreprod.php?id=$1 [L]
RewriteRule ^moreprod/([^/]+)/([^/]+)/$ moreprod.php?id=$1&topid=$2 [L]
RewriteRule ^moreprod/([^/]+)/([^/]+)/([^/]+)/$ moreprod.php?id=$1&topid=$2&catid=$3 [L]
With this code, if you try (for example) to reach http://domain.com/new/moreprod.php?id=123&topid=456&catid=789 then you'll redirect to http://domain.com/new/moreprod/123/456/789/
Conclusion
You can now access your pages via clean urls like
http://domain.com/new/moreprod/123/ (id=123)
http://domain.com/new/moreprod/123/456/ (id=123 and topid=456)
http://domain.com/new/moreprod/123/456/789/ (id=123 and topid=456 and catid=789)
Resolved, just moved these lines to the bottom of .htaccess
RewriteEngine On
RewriteBase /new/
....
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/? [R=301,L]
.....
RewriteCond %{THE_REQUEST} /moreprod\.php\?id=([^&\s]+)&topid=([^&\s]+)&catid=([^&\s]+)&cagid=([^&\s]+)\s [NC]
RewriteRule . moreprod/%1/%2/%3/%4/? [R=301,L]
RewriteRule ^moreprod/([^/]+)/$ moreprod.php?id=$1 [L]
.....
RewriteRule ^moreprod/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ moreprod.php?id=$1&topid=$2&catid=$3&cagid=$4 [L]
# THIS TO THE BOTTOM
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
I got rewrite rules:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www|static)\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301] //add www before adress
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] //remove .php
RewriteRule ^ %1 [R=301]
RewriteCond %{REQUEST_FILENAME} !-d //remove .php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php
RewriteRule ^portfolio/([0-9]+)([^.]*)$ /portfolio-single.php?id=$1 [L]
But the last one dosent work, i want to have adress like www.mysite.com/portfolio/3-some-name => /portfolio-single.php?id=3
I dont know how to get i work.
(Sorry for my bad english)
Change order of rules:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www|static)\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} \s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteRule ^portfolio/([0-9]+) /portfolio-single.php?id=$1 [L,NC,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
I am using the code in below to redirect index.html and non-www version of URL to www. It also removes *.html extensions from the files. Now, I would like to add a trailing slash at the end of the files across all directories. Following are the examples of what I want to get:
www.mydomain.com.au/contact.html goes to www.mydomain.com.au/contact/
www.mydomain.com.au/contact goes to www.mydomain.com.au/contact/
www.mydomain.com.au/glass-replacement/Brisbane.html goes to
/glass-replacement/Brisbane/
and so forth...
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^.*\/index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ /$1 [R=301,L]
RewriteCond %{http_host} ^mydomain.com.au$ [nc]
RewriteRule ^(.*)$ http://www.mydomain.com.au/$1 [r=301,nc,L]
RewriteCond %{THE_REQUEST} \ /(.+/)?index(\.html)?(\?.*)?\ [NC]
RewriteRule ^(.+/)?index(\.html)?$ /%1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+)\.html$ /$1 [R=301,L]
RewriteCond %{SCRIPT_FILENAME}.html -f
RewriteRule [^/]$ %{REQUEST_URI}.html [QSA,L]
Thanks for your help in advance
Try this:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^.*\/index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ /$1 [R=301,L]
RewriteCond %{http_host} ^glassnow.com.au$ [nc]
RewriteRule ^(.*)$ http://www.glassnow.com.au/$1 [r=301,nc,L]
RewriteCond %{THE_REQUEST} \ /(.+/)?index(\.html)?(\?.*)?\ [NC]
RewriteRule ^(.+/)?index(\.html)?$ /%1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+)\.html$ /$1 [R=301,L]
RewriteCond %{SCRIPT_FILENAME}.html -f
RewriteRule [^/]$ %{REQUEST_URI}.html [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.glassnow.com.au/$1/ [R=301,L]