Remove index.php?_route_ in url and replace it with / - .htaccess

Currently I have this on my htaccess but when I go to inner pages of my website the index.php?_route_ is showing up in the middle of the URL. How can I replace that with /?
RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^system/download/(.*) /index.php?route=error/not_found [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]

Right under the RewriteBase / line, add:
RewriteCond %{THE_REQUEST} \ /index\.php\?_route_=?([^&\ ]*)
RewriteRule ^ /%1? [L,R]

Related

Why mode RewriteRule does not work properly?

I make rewrite mode in htaccess but it does not work, why? I want to make nice url www.domain.com/contact from ugly www.domain.com/index.php?route=information/contact
RewriteRule ^contact$ index.php?route=information/contact[L]
here is my current .htaccess
RewriteBase /
RewriteRule ^sitemap.xml$ sitemap/sitemap-index.xml [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^system/download/(.*) /index.php?route=error/not_found [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]
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

http://domain.com/category?page=2 or higher pages not working. Stays on home category or page1

I am using .htaccess redirects to get unique urls for my site. Problem now is I can't for the life of me get category pages higher than page 1 to show.
Below is what my .htaccess file looks like:
RewriteBase /
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|xml|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
RewriteCond%{THE_REQUEST} \ /+index\.php\?_route_=([^\ &]+)
RewriteRule ^ /%1? [L,R]
Ensure we are using HTTPS version of the site.
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Any help please.
If the QSA directive does not work you can try this instead:
RewriteBase /
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|xml|css)
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^([^?]*) index.php?_route_=$1&%1 [L,QSA]
RewriteCond %{THE_REQUEST} \ /+index\.php\?_route_=([^\ &]+)
RewriteRule ^ /%1? [L,R]
# Ensure we are using HTTPS version of the site.
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

how to remove index.php?route= in url using htacess

i am facing problems in ingratiating payment gateway cc avenue. i need to change the url without special charters
my httaccess file is
RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [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]
can any one can help me
Do you mean something like this?
RewriteCond %{THE_REQUEST} \ /+index\.php\?_route_=([^\ &]+)
RewriteRule ^ /%1? [L,R]
#Jon Lin
Thanks your answer. its working form like this;
RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^system/download/(.*) index.php?route=error/not_found [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]
RewriteCond %{THE_REQUEST} \ /+index\.php\?_route_=([^\ &]+)
RewriteRule ^ /%1? [L,R]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.sitenamehere.net/$1 [R,L]

.htaccess redirect url with certain parameters to homepage

The parameters are: "route=product/search" and "path=0". I already tried a lot of things but my knowledge of .htaccess is limited.
I want to redirect the following URL:
www.example.com/index.php?route=product/search&path=0
to
www.example.com
Whatever I try, it doesn't seem to work. What's the best solution for this?
# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [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]
### below send all calls to www
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{QUERY_STRING} (^|&)route=product/search(&|$) [NC]
RewriteCond %{QUERY_STRING} (^|&)path=0(&|$) [NC]
RewriteRule ^index.php$ / [R=301,NC]
add those directives to your main .htaccess:
RewriteEngine on
RewriteCond %{QUERY_STRING} (^|&)route=product/search(&|$) [NC]
RewriteCond %{QUERY_STRING} (^|&)path=0(&|$) [NC]
RewriteRule ^index.php$ /? [R=301,NC]
you have also a RewriteCond missing in the fourth RewriteRule (which prevent url that starts with index.php from the rewrite), your .htaccess would be:
# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteCond %{REQUEST_URI} !^index.php
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
### below send all calls to www
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{QUERY_STRING} (^|&)route=product/search(&|$) [NC]
RewriteCond %{QUERY_STRING} (^|&)path=0(&|$) [NC]
RewriteRule ^index.php$ /? [R=301,NC]

RewriteCond - What am I doing wrong?

I'm using Opencart with the SEO Friendly url's turned on.
That's made the .htaccess file look like this
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]
But I need to add in a folder exception that doesn't get rewritten, specifically /emailer
Looking around the web at answers I did the following:
RewriteCond %{REQUEST_URI} !^/(emailer|js|css)/ [NC]
RewriteRule ^ - [L]
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]
That makes /emailer/ work, but the other rewriting doesn't. Does anyone know what I'm doing wrong here?
You just insert it before the main RewriteRule.
RewriteBase /
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} !^\/(emailer|js|css) [NC]
RewriteCond %{REQUEST_URI} !\.(ico|gif|jpg|jpeg|png|js|css)$ [NC]
RewriteRule ^([^?]*) index.php?_route_=$1&request_uri=%{REQUEST_URI} [L,QSA]
Note: It's not tested, but this should give you the idea how to do it.
Later EDIT:
I have tested my code and it didn't work. I have edited it and it works now, like this:
RewriteCond %{REQUEST_FILENAME} !-f => if the request is not a real filename
RewriteCond %{REQUEST_FILENAME} !-d => if the request is not a real directory
RewriteCond %{REQUEST_URI} !^\/(emailer|js|css) [NC] => if there is not a directory/file in your root that starts with the words emailer/js/css
RewriteCond %{REQUEST_URI} !\.(ico|gif|jpg|jpeg|png|js|css)$ [NC] => if the request does not end with an extension of the following ico/gif/jpg/jpeg/png/js/css
Notes:
to test if you need a forward slash or not in your rewrite rule, append a query variable like i did in my modified example and print it (on the first line after the php open tag) in your index.php file like this:
print_r($_GET['request_uri']);
exit;
After you are done testing, remove the request_uri from htacces and index.php.
Always escape the forward slash with a backslash, like this \ /

Resources