I need to make SEO friendly URLs with URL rewriting from:
http://www.myurl.com/subfolder/index.php?service=example1&location=city1
http://www.myurl.com/subfolder/cars.php?service=example1&location=city1
http://www.myurl.com/subfolder/bicycle.php?service=example1&location=city1
to
http://www.myurl.com/subfolder/example1/example2/index.html
http://www.myurl.com/subfolder/example1/example2/cars.html
http://www.myurl.com/subfolder/example1/example2/bicycle.html
My URL rewriting doesn't work at all,
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^index/(\w+)/?$ index.php?service=$1&location=$2
RewriteRule ^cars/(\w+)/?$ cars.php?service=$1&location=$2
RewriteRule ^bicycles/(\w+)/?$ bicycles.php?service=$1&location=$2
And where should I put the .htaccess file? In the root or a subfolder?
This should probably work:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.html$ /subfolder/$3.php?service=$1&location=$2 [L]
You should put it in the root directory.
Related
I want to redirect several pages to a PHP page with GET variables. However, when I try to use an .htaccess file, it redirects but changes the URL. I don't want it to change the URL structure when redirecting. How would I do this?
For example, I want to redirect /fly-snooze-cruise to http://example.com/package_listing.php?package-type=fly-snooze-cruise
and /fly-snooze-cruise/orlando-airport to http://example.com/package_listing.php?package-type=fly-snooze-cruise&airport=orlando-airport
Here is my .htaccess code:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^fly-snooze-cruise$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise [L]
RewriteRule ^fly-snooze-cruise/orlando-airport$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise&airport=orlando-airport [L]
RewriteRule ^fly-snooze-cruise/orlando-sanford-airport$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise&airport=orlando-sanford-airport [L]
RewriteRule ^fly-snooze-cruise/melbourne-airport$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise&airport=melbourne-airport [L]
RewriteRule ^snooze-park-cruise$ http://www.example.com/package_listing.php?package-type=snooze-park-cruise [L]
i have following htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteRule !^/?(maintenance\.html|.*\.css|.*\.js)$ http://www.example.com/maintenance.html [R=302,L]
RewriteRule ^([A-Za-z0-9]+)$ $1.php
RewriteRule ^home\.php$ index.php
RewriteRule ^home$ index.php
as you can see all, no matter which page you visit on the website it will be redirected to maintenance.html. I also need a small change that will exclude one more location from this. Since I am using Magento, I need to exclude admin area from this redirect so I think these are the urls that I need
http://www.example.com/index.php/admin_852_in
http://www.example.com/skin/
http://www.example.com/js/
http://www.example.com/media/
What rule should I add for these two urls too?
thanks!
You can tweak your exclusions like this:
Options +FollowSymLinks
RewriteEngine on
RewriteRule !^/?(maintenance\.html$|index\.php/admin|css/|js/|.*\.(css|js)$) http://www.example.com/maintenance.html [R=302,L,NC]
I've got an address like this:
/?pid=74&sid=381:naprawairegeneracjaturbosprezarek24hjozefkrezolek
and i want to have:
/74:381:naprawairegeneracjaturbosprezarek24hjozefkrezolek
or better:
/naprawairegeneracjaturbosprezarek24hjozefkrezolek
my .htaccess
Options -Multiviews
RewriteEngine On
RewriteBase /
RewriteRule ^([a-z]+):([a-z]+):([a-z]+)$ /index.php?pid=$1&sid=$2:$3 [L]
I have also rewrite rule to delete index.php from url
RewriteRule ^([0-9]+):([0-9]+):([a-z]+)$ /index.php?pid=$1&sid=$2:$3 [L]
You cannot achieve /naprawairegeneracjaturbosprezarek24hjozefkrezolek unless you make sure that index.php can find the correct item with only that parameter.
I just transfered my Domain to a new Server. Mod_Rewrite is enabled on the new server but unfortunately some RewriteRules don't work, while others do. I haven't changed anything in the .htaccess
So the URL www.mydomain.com/go/10.html should make an internal redirect to www.mydomain.com/go.php?name=10
The snippet in the .htaccess looks like this:
# go.php
RewriteRule ^go$ "$0/" [R=301,L,QSA]
RewriteRule ^go/$ go.php [L,QSA]
RewriteRule ^go/.*?([^\.\/]*)\.html$ go.php?name=$1 [L,QSA]
The $_GET["name"] is not available if I call this url.
Replace your .htaccess code with this.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(go)/([^.]+)\.html$ /$1.php?name=$2 [L,QSA,NC]
I want this URL:
http://www.mydomainblabla.com/s/can+you+drill+shrinky+dinks?.html
to be rewritten to this one:
http://www.mydomainblabla.com/search.php?q=can+you+drill+shrinky+dinks?
I am using this mod_rewrite rule in my .htaccess to accomplish this
RewriteRule ^s/(.+).html$ search.php?q=$1 [L,QSA]
However, the result is not as I want it, when I go to the first url, I get a page not found message.
The same problem occurs when I visit this url:
http://www.mydomainblabla.com/s/http://www.zakgeldnodig.nl/.html
which should be rewritten into this one:
http://www.mydomainblabla.com/search.php?q=http://www.zakgeldnodig.nl/
What modifications should I make to my .htaccess to make this work?
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+s/(.+?)\.html [NC]
RewriteRule ^ search.php?q=%1 [L,NE]