I want Rewrite rule for .htaccess for change URL like below..
From
http://www.example.com/templates/professional_website/news.php?ac=post&id=2&p=1
To
https://www.example.com/templates/professional_website/news/post/2/1
Untested answer taken from a random linked question:
RewriteEngine on
RewriteRule ^templates/professional_website/news/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ templates/professional_website/news.php?ac=$1&id=$2&p=$3 [L,NC,QSA]
RewriteRule ^templates/professional_website/news/([^/\.]+)/([^/\.]+)/?$ templates/professional_website/news.php?ac=$1&id=$2 [L,NC,QSA]
Related
Quick question. I am currently making my first tentative few steps into the world of regex and I'm struggling with a URL rewrite i am attempting. Basically i need the rewrite rule to rewrite several urls all which will contain a common sub string and all of which will rewrite to the same sub path eg http://www.example.co.uk/test/folder will rewrite to http://www.example.co.uk/new/subfolder and http://dev.example.co.uk/new/subfolder will also rewrite to http://www.example.co.uk/new/subfolder etc. any body got any ideas?
Thanks
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.co\.uk$ [NC]
RewriteRule ^test/(.+)$ /new/$1 [L,NC]
RewriteCond %{HTTP_HOST} ^dev\.example\.co\.uk$ [NC]
RewriteRule ^(new/.+)$ http://www.example.co.uk/$1 [L,NC,R=302]
Is it possible to create a rewrite code that includes a wildcard?
for example any request for:
http://example.com/something1/something2/*
would redirect to:
http://example.com/newthing
AND
will it matter where in the .htaccess file I place the rewrites?
This should work for you:
RewriteEngine On
RewriteRule ^something1/something2/(.*)$ /$1 [R=302,L]
It should change http://example.com/something1/something2/test to http://example.com/test
EDIT:
RewriteEngine On
RewriteRule ^shirts/(.*)$ /clothing.html [R=301,L]
How to rewrite
/?custom_ref=
with
/?ref=
using htaccess rewrite???
RewriteEngine On
RewriteCond %{QUERY_STRING} custom_ref=(.*)
RewriteRule (.*) /?ref=%1 [R=301,L]
Can you please tell me the directory/file that you using this query on so I make sure this code will only work with it.
I have url pattern like this.
site.com/page-name?variable-name=variable value
I want this to be site.com/variable - value
I' am not good in rewrite api. Please guide me through .htaccess.
Try this
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)=(.*)
RewriteRule ^(.*) /%1-%2? [R,L]
I'm trying to set up a rewrite that will redirect this URL:
/video-2011.php?video=150
to this:
/video/150/freeform-title-text-here/
I have the rewrite working using this line in my HTACCESS:
RewriteRule ^video/([0-9]+)/(.*)$ video-2011.php?video=$1 [L]
But as soon I add R=301 into the mix, it breaks. Any ideas?
Here's the full HTACCESS when it breaks:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^video/([0-9]+)/(.*)$ video-2011.php?video=$1 [R=301,L]
Any help is greatly appreciated, thanks!
I think you might be missing a line from your .Htaccess.
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^video/([0-9]+)/([a-z0-9-_]+)$ video-2011.php?video=$1 [L]
#New
RewriteCond %{REQUEST_URI} !^/video/([0-9]+)/([a-z0-9-_]+)/?$
RewriteCond %{QUERY_STRING} ^video=([0-9]+)&name=([a-z0-9-_]+)/?$
RewriteRule ^video-2011.php$ video/%1/%2/? [R=301,L]
I assuming you want to rewrite the url if it is:
/video/150/freeform-title-text-here/
And redirect the url if it is:
/video-2011.php?video=150
to:
/video/150/freeform-title-text-here/
So this way it keeps the urls looking pretty and tidy.
Please correct me if I am wrong.
Edit
I've added in a RewriteCond to stop the second rewrite happening.
As the first rule will obviously rewrite:
/video/150/freeform-title-text-here/
Which means the query string you don't see:
/video-2011.php?video=150
Would of made the second rule happen too.
Can you try:
RewriteRule ^video/([0-9]+)/ /video-2011.php?video=$1 [R=301,L,NC,QSA]
And yes it will redirect /video/150/foo to /video.php?video=150 not the other way around as you've stated in your question.