how to use multiple url RewriteRule in .htaccess - php

this is working
RewriteRule ^([a-zA-Z0-9_-\s]+)-([a-zA-Z0-9_-\s]+)\.html$ detail.php?category=$1&model=$2
this is working
RewriteRule ^([a-zA-Z0-9_-\s]+)\.html$ brand.php?brand=$1
this is not working
RewriteRule ^([a-zA-Z0-9_-\s]+)\.htm$ colour.php?colour=$8
only two rule working how to use multiple rewrite rule using .htaccess

if i use like this ^colour/([a-zA-Z0-9_-\s]+)\.htm$ colour.php?colour=$1 then it is working with out colour/ this it is not working
This problem seems to be due to enabling of MultiViews. Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php.
To disable this use this line at top of your .htaccess:
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^colour/([\w\s-]+)\.htm$ colour.php?colour=$1 [L,QSA,NC]

Related

URL rewrite rule is not working in php

i am using godaddy hosting and addon domain. i want to make my long url to short url.
for example my url is follwing:
www.example.com/events/landing_event.php?url=text-first
and i want following url:
www.example.com/events/text-first
for this i am using following rewrite url in .htaccess file
RewriteRule ^([a-zA-Z0-9-/]+)$ events/landing_event.php?url=$1 [L]
RewriteRule ^([a-zA-Z0-9-/]+)/$ events/landing_event.php?url=$1 [L]
but this rewrite rule is not working.
so please help how can i make short url.
Use this source after you make sure RewriteEngine Enabled and On
RewriteEngine On
RewriteRule ^events/([^/]*)$ /events/landing_event.php?url=$1 [L]
The original URL:
http://www.example.com/events/landing_event.php?url=text-first
The rewritten URL:
http://www.example.com/events/text-first
Updated with 500 Internal Server Error
Your code is guaranteed to generate 500 internal server error because it is causing infinite looping. Reason is that your matching URI pattern is: ^events/([^/]*)$
Which matches your URLs before and after rewrites. And once it reaches max allowed internal rewrite limit Apache throws 500 internal server error and bails out.
Change your code to this
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^events/([^/]*)$ /events/landing_event.php?url=$1 [L,QSA,NC]
Try this code :
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /events/landing_event.php?url=$1 [L]
Add this in your .htaccess file
You can see there are many ways to achieve that goal.
Also
RewriteEngine On
RewriteRule ^events/([^/]*)\.html$ /events/landing_event.php?url=$1 [L]
would do the job. So basicly, how does the full scope of your project urls look like?
Like do you always want to print the parameters? If yes, also the name sometimes or also the value?
The newer versions of apache requires you to change AllowOverride on /etc/apache2/apache2.conf
from
AllowOverride None
to
AllowOverride All

Cant redirect my URL with htaccess

I am using WAMP and my url is localhost/hotel/hotels.php?id=21
Using rewrite rule as follow,
Options +FollowSymLinks
RewriteEngine on
RewriteRule hotels/id/(.*)/ hotels.php?id=$1
RewriteRule hotels/id/(.*) hotels.php?id=$1
But nothing happens..
My mod_rewrite is on and also changes done in httpd.conf file.
Please give me a suggestion to handle the issue?
You must use flags for your RewriteRule. You can change it as follow
RewriteEngine on
RewriteRule ^hotels/id/([\d]+)/?$ hotels.php?id=$1 [NC,L]
You can call your pages from
localhost/hotel/hotels/id/12
If your .htaccess file is located in localhost/hotel .

Apache rewrite rule works on localhost but not on server

I have a site that I would like to use Apache's RewriteRule to rewrite URLs.
I want:
http://baileyseymour.com/index.php?p=home
to rewrite to
http://baileyseymour.com/p/home
I have AMPPS installed on my Mac and I added the following lines to httpd.conf and they work successfully:
RewriteEngine On
RewriteRule ^/p/(.*) /index.php?p=$1 [PT]
I'm trying to do the same but on my server.
And I have added the same apache code to /public_html/.htaccess but I get the error message below:
Not Found
The requested URL /p/home was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
The exact same code works on my localhost server. Why not on my website?
Can you check your remote server apache supports "AllowOverride All" ?
also try this way maybe it will help.
RewriteEngine On
RewriteRule ^p/(.*) /index.php?p=$1 [PT]
but you may have to modify $_GET['p'] properly. which will be sent only "home" part.
You need to remove the leading slash from the rewrite rule's pattern. URI's have their leading slash removed when the rewrite engine applies rules in an htaccess file.
RewriteEngine On
RewriteRule ^p/(.*) /index.php?p=$1 [PT]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.baileyseymour\.com
RewriteRule ^(.*)$ http://www.baileyseymour.com/$1 [R=301,L]
</IfModule>
.htaccess is the right place to put them and that file should be in the same directory as your default home page.

.htaccess modrewrite not redirecting my links

I'm changing my website links to a SEO friendly urls, I did every thing in php file and changed the urls as following:
http://mywebsiet.com/news-details.php?id=2012/6/21/newstitle.html
how can I redirect to:
http://mywebsiet.com/2012/6/21/newstitle.html
I tried this Generating tool from www.generateit.net/mod-rewrite/
and created the .htaccess with the code provided:
RewriteEngine On
RewriteRule ^([^_]*)$ /news-details.php?id=$1 [L]
and even so, nothing get changed.... any ideas?
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 /
RewriteRule ^(.+?\.html)$ /news-details.php?id=$1 [L,QSA,NC]

Why doesn't this mod_rewrite rule work?

When I try to use this rule:
RewriteEngine On
RewriteRule ^articleID/([^/]*)$ /viewArticle.php?articleID=$1 [L]
It sends me to a 404 page.
I am not well-versed in how to use an htaccess, so I most likely did something wrong. I generated it with a tool at generateit.net
I'm trying to access http://majornoob.com/devel/testdesign/articleID/5 which would equal http://majornoob.com/devel/testdesign/viewArticle.php?articleID=5
Try to add a RewriteBase:
RewriteBase /
Also make sure that your server accept htaccess files. Does the Server configure contains a AllowOverride all statment in your Directory Directive.
With the path, it should work:
RewriteRule articleID/([^/]*)$ /devel/testdesign/viewArticle.php?articleID=$1 [L]

Categories