How do you create one rule overriding rules for individual pages? - .htaccess

I have:
RewriteRule ^for-auto.html index.php?show=for-auto [L]
RewriteRule ^for-home.html index.php?for=dla-home [L]
RewriteRule ^cleaning-service.html index.php?show=cleaning-service [L]
How to create one rule for all of the pages above?

You can try this Rule :
RewriteRule ^(.+)\.html$ index.php?show=$1 [L,NC]
Reference : http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
Hope this helps you!

Related

.htaccess rewrite category filters

I'm wondering if it's possible to write these lines into one
RewriteRule ^([^/]*)/sd$ /category.php?category_id=$1 [L,NC]
RewriteRule ^([^/]*)/sd/(.*)$ /category.php?category_id=$1&filters=$2 [L,NC]
I've tried with
RewriteRule ^([^/]*)/sd/?(.*)$ /category.php?category_id=$1&filters=$2 [L,NC]
but it doesn't works.
Thanks in advance.

Rewriting Parameters to Subfolder Structure (htaccess)

I am looking to rewrite 2 parameters to form a cleaner structure:
CURRENT: ?fruit=Oranges&vegetable=Carrots
DESIRED: /oranges-vs-carrots/
Any comments or explanation on the regex would be really appreciated.
Try :
RewriteEngine on
RewriteCond %{THE_REQUEST} \?fruit=([^&]+)&vegitable=([^\s]+) [NC]
RewriteRule ^ /%1-vs-%2? [NC,R,L]
RewriteRule ^([^-]+)-([^/]+)/?$ /?fruit=$1&vegitable=$2 [NC,L]
RewriteRule ^([a-z]+)-vs-([a-z]+)/$ ?fruit=$1&vegetable=$2
site for testing it: http://martinmelin.se/rewrite-rule-tester/

htaccess add query to the end of the link

I need to know how to redirect
http://test.com/test.php to http://test.com/test.php?var=foo
& also if it's http://test.com/test.php?var=foo to be http://test.com/test.php?var=foo&var2=foo
If this will cause a loop just tell me how to achieve it and I am going to test
Thanks in advance
You can use these rules:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^([^.]+\.php)$ /$1?var=foo [L]
RewriteCond %{QUERY_STRING} (?:^|&)var=foo(?:&|$)
RewriteRule ^([^.]+\.php)$ /$1?var2=foo [L,QSA]

Always rewrite a baseurl to /my-page

For many reasons, I need to rewrite my Base URL to a page, which is a hub.
i.e. http://data.mydomain.com always directs the user to http://data.mydomain.com/my-page
What's the best way to do this?
Use this
RewriteCond %{REQUEST_URI} !^/my-page
RewriteRule ^(.*)$ /my-page/$1 [L,R=301]
Did you try anything?
/?$ /my-page
Add this in you htaccess :
RewriteEngin on
RewriteCond %{HTTP_HOST} ^data.mydomain.com$
RewriteRule ^/?$ /my-page [L,R=301]

trying to rewrite url in htaccess

I have url
http://www.url.com/business/index.php?biz=andrewliu
I'm trying to accomplish so it will be
http://www.url.com/business/andrewliu
I tried to have this:
RewriteRule ^/?([a-z0-9_-]+)/?$ /index.php?biz=$1 [L]
or
RewriteRule ^/?([a-z0-9_-]+)/?$ /business/index.php?biz=$1 [L]
doesn't work?
Help me?
Edit:
I have this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
prior to the rewriterule
That depends in which directory your .htaccess file is.
For the root directory try this one:
RewriteRule ^/?business/([a-zA-Z0-9_-\.]+)/?$ /business/index.php?biz=$1 [L]
If your .htaccess file is in the business directory that of your statments should work fine:
RewriteRule ^/?([a-zA-Z0-9_-\.]+)/?$ /index.php?biz=$1 [L]
RewriteRule ^business/([_0-9a-zA-Z-]+)/?$ business/index.php?b=$1 [L]
It's not clear from your examples whether you want "biz" or "business" or "b". I'm taking a guess that you want "biz", in which case your rule should be:
RewriteRule business/(.*) /index.php?biz=$1 [L]
Or maybe you want:
RewriteRule ([^\/]*)/(.*) /index.php?$1=$2 [L]

Resources