I had rewrite a URL from example.com/service.php?p_id=1&s_id=seo to example.com/1/seo/.
By The following rule:
this rule is for example.com/services.php?p_id=1&s_id=seo
RewriteEngine On
RewriteCond %{THE_REQUEST} /services\.php\?p_id=([^&\s]+)&s_id=([^&\s]+) [NC]
RewriteRule ^ /%1/%2/? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ services.php?p_id=$1&s_id=$2 [QSA,L]
Now the problem is that when i use the following rule for another url like example.com/about-us.php?p_id=1&s_id=2 and for example.com/it-training.php?p_id=1&s_id=2 then the url redirects as example.com/1/2/index.php but it should be as example.com/1/2 ,
formated rule for about-us.php is given bellow
RewriteEngine On
RewriteCond %{THE_REQUEST} /about-us\.php\?p_id=([^&\s]+)&s_id=([^&\s]+) [NC]
RewriteRule ^ /%1/%2/? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ about-us.php?p_id=$1&s_id=$2 [QSA,L]
In other case i have some url like example.com/packages.php, index.php, i also want to remove the .php from that kind of files
Related
I have a page where i am listing all my products. But i want the same page on different url also. So the both urls should open same page with any redirect.
Original URL is: http://example.com/product/all-products
New URL with same content should be http://example.com/all-products
How can i do that with .htaccess?
Try the below rule
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([\w-]+)$ product/$1 [L]
You can use the following in /root.htaccess :
RewriteEngine on
#1 redirect browser url from "/product/foobar" to "/foobar"
RewriteCond %{THE_REQUEST} /product/(.+)\sHTTP [NC]
RewriteRule ^ /%1 [L,R,NE]
#2 if "/foobar" exists as a file or dir in product folder
RewriteCond %{DOCUMENT_ROOT}/product/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/product/$1 -d
#3 then rewrite "/foobar" to "/product/foobar"
RewriteRule ^(.*?)/?$ /product/$1 [L]
If the example above fails, you could try the following
RewriteEngine on
RewriteCond %{THE_REQUEST} /product/(.+)\sHTTP [NC]
RewriteRule ^ /%1 [L,R,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /product/$1 [L]
I am trying to rewrite an ugly URL that's using two properties. For example, I want example.com/stories/?url=how-are-you?num=5 to be example.com/stories/how-are-you/5 I have rewritten the first property, but I don't know how to rewrite the num property. Here's my .htaccess file:
RewriteEngine On
RewriteBase /stories/
RewriteCond %{THE_REQUEST} /\?url=([^&\s]+) [NC]
RewriteRule ^ %1? [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?url=$1 [L,QSA]
Try :
RewriteEngine On
RewriteBase /stories/
RewriteCond %{THE_REQUEST} /\?url=([^&\s]+)&num=([0-9]+) [NC]
RewriteRule ^ %1/%2? [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?url=$1&num=$2 [L,QSA]
I want to redirect all dynamic links to redirect to its rewritten url eg:
http://www.example.in/ads-detail.php?location=Mumbai&id=37&name=sudha-restaurant
to
http://www.example.in/Mumbai/37/sudha-restaurant
My htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /ads-detail.php?location=$1&id=$2&name=$3 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)$ /ads-detail.php?id=$1&name=$2 [QSA,L] –
Tried alot i haven't got any solution please help , Thanks in advance
Try this in your htaccess :
RewriteEngine on
#1) redirect "/ads-detail.php?location=foo&id=123&name=bar" to "/foo/123/bar"
RewriteCond %{THE_REQUEST} /ads-detail.php\?location=([^&]+)&id=([^&]+)&name=([^\s]+) [NC]
RewriteRule ^ /%1/%2/%3? [NC,L,R]
#2) if the requested is not for an existing directory
RewriteCond %{REQUEST_FILENAME} !-d
#3) then rewrite "/foo/123/bar" to "ads-details.php"
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /ads-detail.php?location=$1&id=$2&name=$3 [NC,L]
i want rewrite my url
this is my index.html page
Main <br>
About <br>
Contact <br>
this is my .htacees file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/([a-z])/([0-9])?$ index.php?url=$1&page=$2 [L]
i want change my url to
http://localhost/htac/index/about/2 (http://localhost/htac/index/{url}/{page})
but url is :
http://localhost/htac/index.php?url=about&page=2
Have your /htac/.htaccess like this:
RewriteEngine on
RewriteBase /htac/
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /index\.php\?url=([^\s&]+)&page=([^\s&]+) [NC]
RewriteRule ^ %1/%2? [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?url=$1&page=$2 [L,QSA]
You need to change source of your HTML to have links as: Main
I have some URL:
index.php?controller=user&method=show&id=7
in this URL: controller,method and show, are my keys
user, show and 7 are some kind of value
I would like translate URL to:
index.php?user/show/7
Is there any posibilities to translate this URL in .htaccess file?
Now, my .htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /Cobbler/index.php
I don't see the benefit of this but you can replace your current code by this one
RewriteEngine on
RewriteBase /Cobbler/
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule . ./ [R=301,L,QSA]
RewriteCond %{QUERY_STRING} ^([^/]+)/([^/]+)/([^/]+)$
RewriteRule ^$ index.php?controller=%1&method=%2&id=%3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]