Below is the code which i use to url rewrite in our .htaccess file
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule pages/(.*)/? /page/index.php?name=$1 [NC,L]
from the above code if the url is www.example.com/pages/2 then actually it goes to url www.example.com/page/index.php?name=2
but also i want something like this : if a page request is www.example.com/pages/2/user/rahul then it should also go to same url www.example.com/page/index.php?name=2&user=rahul
so doing the above thing i did something like this :
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule pages/(.*)/? /page/index.php?name=$1 [NC,L]
RewriteRule pages/(.*)/user/(.*)/? /page/index.php?name=$1&user=$2 [NC,L]
but it does't work how i want.
Try :
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^pages/([^/]+)/user/([^/]+)/?$ /page/index.php?name=$1&user=$2 [NC,L]
RewriteRule ^pages/([^/]+)/?$ /page/index.php?name=$1 [NC,L]
Related
I have a php page and i'm trying to map it with htaccess. The idea is to map the page and if there are no parameters, the page is 1. this is for pagination.
My php page:
<?php echo $page = isset($_GET['p']) ? $_GET['p'] : 1; ?>
In my htaccess file i have this:
RewriteRule ^noticias/ noticias.php [L]
RewriteRule ^noticias/([0-9]+)/?$ noticias.php?p=$1 [L]
If i try to access the page with localhost/example/noticias.php and localhost/example/noticias.php?p=2 everything works.
If i add the first rule, the second rule does not work. And if i remove the first rule, the url wont work.
Tks in advance.
You may use these rules with MultiViews turned off:
Options -MultiViews
RewriteEngine on
RewriteRule ^(noticias)/?$ $1.php [NC,L]
RewriteRule ^(noticias)/(\d+)/?$ $1.php?p=$2 [QSA,NC,L]
Try this in your .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^noticias/?$ noticias.php [QSA,NC,L]
RewriteRule ^noticias/([1-9]+)/?$ noticias.php?p=$1 [QSA,NC,L]
</IfModule>
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 help in URL rewriting of my own. My URL structure is looks like
http://domain.com/products-details.php?id=14
What i want it to be something like http://domain.com/products/14/
What i have tried so far is this in my .htaccess file
ErrorDocument 404 /myproject/notfound.php
Options +FollowSymlinks
RewriteEngine on
RewriteBase /myproject/
RewriteRule ^products/([^/]+)$ products-detail.php?id=$1 [QSA]
The above rule works fine without the trailing slash at the end, but i do want the slash at the end.
Further more:
It would be great if the non-rewrite request gets redirected to the rewrite ones. Thank you:)
You need a new rule for redirect:
ErrorDocument 404 /myproject/notfound.php
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /myproject/
RewriteCond %{THE_REQUEST} /products-detail\.php\?id=([^\s&]+) [NC]
RewriteRule ^ products/%1? [R=302,L,NE]
RewriteRule ^products/([^/]+)/?$ products-detail.php?id=$1 [NC,L,QSA]
I'm attempting to perform a simple 301 redirect via htaccess, the redirect works but adds "?folder=X" to the URL.
For instance:
Redirect 301 /pets http://www.mydomain.com/discount-pet-products
Returns:
http://www.mydomain.com/discount-pet-products?folder=pets
How do I remove this?
Here is my htaccess file
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
Redirect 301 /pets http://www.mydomain.com/discount-pet-products
RewriteRule ^([0-9a-zA-Z-]+)$ load.php?folder=$1 [L]
Try this:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^/pets$ http://www.mydomain.com/discount-pet-products? [R=301,L]
RewriteRule ^([0-9a-zA-Z-]+)$ load.php?folder=$1 [L]
Try this code:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^pets/$ /discount-pet-products? [R=301,L]
RewriteRule ^([0-9a-zA-Z-]+)/?$ load.php?folder=$1 [L,QSA]
Make sure to test this in a new browser to avoid browser caching issues.
The answer was placing redirect at top of .htaccess file, before anything
RewriteRule ^pets$ http://www.mydomain.co.uk/discount-pet-products [R=301,L]
I'm try to rewrite my url
http://www.domain.com/live/randomword
it should go rewrite to
http://www.domain.com/live/?cat=randomword
here are my tests:
RewriteRule ^live/(.*)$ /live/?cat=$1
RewriteRule ^live/(.*)$ live/?cat=$1
and all i have in the htaccess file is:
RewriteEngine on
You should try to add a RewriteBase / to your .htaccess and to suffix your rule with a [L] to say it's last rewrite rule ending with something like that:
RewriteEngine on
RewriteBase /
RewriteRule ^live/(.*)$ live/index.php?cat=$1 [L]
If this still doesn't work be sure to check that mod_rewrite is enabled
also you can do a [R,L] instead of [L] to see the redirection in the url and so have more info on what's going own.
hope this help
Have this code in your .htaccess file:
Options -MultiViews +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^live/(.*)$ /live/?cat=$1 [L,NC]
in rewrite rule the file name or extension in missing?
write rule like,
RewriteRule ^live/([a-zA-Z0-9_-]+)$ /viewcategory.php?cat=$1