How can I rewrite this URL using .htaccess?
or just hide ?lang=es.
http://website/services?lang=es
to:
http://website/services/es
Try this in a .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^services/([a-zA-Z]{2})/?$ /services?lang=$1 [QSA,L]
</IfModule>
Related
When i click on a link it should redirect to
for ex; www.domain.com/demo/item.php?item=abc&id=3
but in url it should show as www.domain.com/demo/abc/3
im Using
<IfModule mod_rewrite.c>
Options +SymlinksIfOwnerMatches
RewriteEngine on
RewriteRule ^demo/(.+) demo/item.php?item=$1&id=$2 [NC,L]
Please help
You can try with this one, it will not redirect your URL but if you execute your URL (www.domain.com/demo/abc/3) it will be work.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^demo/([0-9a-zA-Z\s_]+)/([0-9]+)(/?)$ demo/item.php?item=$1&id=$2 [NC,L]
You could try like this after adding the rewritebase directive
RewriteEngine on
RewriteBase /
RewriteRule ^demo/([0-9a-zA-Z\s_]+)/([0-9]+)(/?)$ demo/item.php?item=$1&id=$2 [NC,L]
I need to rewrite this url
category.php?cat=computers
to
category/computers
Or, is it the other way round?
How do I do that with .htaccess?
The rule is:
RewriteRule ^category/(.+)/?$ category.php?cat=$1 [NC,L]
your .htaccess should look like this:
<IfModule mod_rewrite.c>
#if the name of the php file is the same of the path, you have to remove MultiViews
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteRule ^category/(.+)/?$ category.php?cat=$1 [NC,L]
</IfModule>
htaccess redirection is working perfectly in my localhost wampserver. But when uploaded to server(to my site) names with rewrite rule contains "-" is not working.
For example - below code is working:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^supportus/{0,1}$ supportus.php [QSA,L]
</IfModule>
But this isn't working:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^arts-exhibitions/{0,1}$ arts.php [QSA,L]
</IfModule>
For some reason it needed "/" and only $. The below code is working perfectly.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^art-exhibitions$ /arts.php [QSA,L]
</IfModule>
Ive been trying this commands, but with no luck :
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^product/(.*+) product.php?name=$1
Make sure your mod_rewrite rules are inside an IfModule:
<IfModule mod_rewrite.c>
#...
</IfModule>
The rule you have will reroute example.com/product/foo to example.com/product.php?name=foo.
If you want to route example.com/foo to example.com/bar.php?name=foo you can do this:
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^([^/]*)$ /bar.php?name=$1 [L]
</IfModule>
so it will looks like this?
Options +FollowSymLinks
RewriteEngine on
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^([A-Za-z0-9]+)$ product.php?name=$1 [L]
</IfModule>
Ive been trying lot of Rewrite Rules, but nothin happens the script and .htaccess are in same directory of course
I'm trying to redirect a folder to a file.
I want to redirect:
www.mysite.com/category/customername
AND
www.mysite.com/category/customername/
TO
www.mysite.com/category.php?customer=customername
This is working, but "customer" become "customername.php" and not "customer"
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^category/(.*)$ category.php?customer=$1 [L]
How could i remove ".php" via .htaccess?
Thank you!
You can use:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^category/([\s\w-]+)/?$ category.php?customer=$1 [L,NC,QSA]
Thank you anubhava, i have do a dynamic rule:
RewriteRule ^(.+[^/])/(\w+)/?$ $1.php?customer=$2 [L]
Tested for
www.mysite.com/category_1/customer AND
www.mysite.com/category_1/customer/
www.mysite.com/category_2/customer AND
www.mysite.com/category_2/customer/
www.mysite.com/category_X/customer AND
www.mysite.com/category_X/customer/
Bye