I want to rewrite url as following.
This is url : http://www.xyzdomain.com/?page=9
i want it like this : http://www.xyzdomain.com/9
Add this to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+\?page=([0-9]+)
RewriteRule ^ /%1? [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)$ /?page=$1 [L,QSA]
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 want to enter http://localhost:81/admin/dashboard in my browser but the request should be http://localhost:81/admin/index.php?page=dashboard.
The mod_rewrite is enabled and i tried this in the .htaccess but it didn't work. The .htaccess is located in htdocs/admin/.htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ index.php?page=$1 [NC]
You can match the trailing slash optionally by adding a ? next to it in the pattern :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?page=$1 [NC]
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]
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