I need to convert the link in my website to this way :
wwww.example.com/tut/1
from
wwww.example.com/tut.php?v=1
I tried alot of way but no thing happen
my code was this
RewriteEngine On
RewriteRule ^tut/(\d+) tut.php?v=$1 [QSA,L]
is there is any other idea or code ??
You can use this code in root .htaccess:
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /tut\.php\?v=(\d+) [NC]
RewriteRule ^ /tut/%1? [R=302,L,NE]
RewriteRule ^tut/(\d+)/?$ tut.php?v=$1 [QSA,L,NC]
Related
I guess it's an easy question but I hardly know syntax used in .htaccess, so I got a bit stuck. How to add '/de/' after a domain name in this case, so the result will be something like 'blablabla.com/de/blog' or 'blablabla.com/de/offices' instead of 'blablabla.com/blog' and 'blablabla.com/offices'?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_COOKIE} lang=de [NC]
</IfModule>
I know that there should be RewriteRule after RewriteCond but, as I've said before, I'm not familiar with the syntax...
You can use:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_COOKIE} lang=de [NC]
RewriteCond %{REQUEST_URI} !^/de/ [NC]
RewriteRule ^(.*)$ /de/$1 [R,L]
</IfModule>
To access your site urls with /de segment ,you can use :
RewriteEngine On
RewriteBase /
RewriteRule ^de/(.+)$ /$1 [NC,L]
Currently my localhost URL is like localhost/apnaujjain/page.php?page_id=1&action=contacts
Now I want to write a rule so that when I go to above url it just rewrite the url like localhost/apnaujjain/contacts.html
See it should convert .php into .html without affect page content.
Until now I've tried
Options +FollowSymLinks -MultiViews
RewriteEngine on
#RewriteBase /
RewriteCond %{THE_REQUEST} (.*)\.php
RewriteRule ^(.*)\.php $1.html [R=301,L]
RewriteCond %{THE_REQUEST} (.*)\.php?page_id=1$&action=2$
RewriteRule ^(.*)\.php $2.html [R=301,L]
RewriteCond %{THE_REQUEST} (.*)\.html
RewriteRule ^(.*)\.html $1.php [L]
But it's not working.
You can use this code in /apnaujjain/.htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /apnaujjain/
# redirect localhost/apnaujjain/page.php?page_id=1&action=contacts to
# localhost/apnaujjain/1/contacts.html
RewriteCond %{THE_REQUEST} \s/+.+?\.php\?page_id=([^\s&]+)&action=([^\s&]+) [NC]
RewriteRule . %1/%2.html? [R=301,L]
RewriteRule ^([^/]+)/([^.]+)\.html$ page.php?page_id=$1&action=$2 [NC,L,QSA]
trying to redirect this query to a new domain:
www.domain.com/search.php?q=keyword
to
www.newdomain.com/search.php?q=keyword
keyword can be any word
And want to keep the rest in domain, I just need to redirect this query.
I try several ways and the one I found closer to solution is this one:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^q=1$
RewriteRule ^search\.php$ http://www.newdomain.com/search.php?q=$1 [R=301,L]
but does not work!
Hope someone could help me correcting this and also if this is the best way to do the job?
Many thanks.
You're pretty close.
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 %{HTTP_HOST} ^(www.)?domain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^q=.+ [NC]
RewriteRule ^(search\.php)$ http://www.newdomain.com/$1 [R=301,L,NC]
Try this
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=123$
RewriteRule ^/?product\.php$ http://website.com.au/product_123.php? [L,R=301]
Or
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=([^&]+)
RewriteRule ^/?product\.php$ http://website.com.au/product_%1.php? [L,R=301]
this works and is simple
RewriteEngine on
RewriteRule ^(.*)$ http://newdomain.com/$1 [QSA]
I'm trying to redirect article.php?title=variable to variable/ using .htaccess but I'm not really sure what is wrong with my code. If I go to http://site.com/variable/ it is redirecting me to http://site.com/article.php//?titlu=article.php
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
#Rewrite urls for article
RewriteRule ^(.*)/$ article.php?titlu=$1
RewriteRule ^(.*)$ /$1/ [R]
</IfModule>
You have to capture the query string. This should work for you.
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} title=([A-Za-z0-9_.-]*)
RewriteRule ^article.php /%1/? [R=301,L]
I'm assuming you don't want to redirect slashes... if you do you could add them to the string as well (or accept all characters).
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} title=(.*)
RewriteRule ^article\.php /%1/? [R=301,L]
It seems a very eask task, but I couldn't make it for hours after reading too much tutorial. Please help..
I need to redirect
http://example.com/myfolder/myfile.php?type=1&add=20
to this address:
http://example.com/newfolder/mytasks.xml
I tried too many. My last tryout was this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/myfolder/myfile.php?type=1&add=20$ /newfolder/mytasks.xml [R=301,NC,L]
</IfModule>
Use this rule instead:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+myfolder/myfile\.php\?type=1&add=20 [NC]
RewriteRule ^ /newfolder/mytasks.xml [R=301,L]
Remember:
RewriteRule match doesn't start with a slash /
RewriteRule doesn't match query string, it matches only Request URI
If you also want the query type=1&add=20 removed, something like this should work:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} type=1&add=20 [NC]
RewriteCond %{REQUEST_URI} !/newfolder/ [NC]
RewriteRule ^myfolder/myfile\.php /newfolder/mytasks.xml? [R=301,NC,L]
Redirects:
http://example.com/myfolder/myfile.php?type=1&add=20 to
http://example.com/newfolder/mytasks.xml
For silent mapping, replace [R=301,NC,L] with [NC,L]