I have a url
www.abc.com/description.php?id=123035
when I write a url like
abc.com/123035/Four_Seasons_Hotel_Istanbul_at_Sultanahmet
I want to get the result. Rewrite won't see "Four_Seasons_Hotel_Istanbul_at_Sultanahmet" will see only id and will work.
How can that be done?
I have tried this
Options +FollowSymlinks
# Prevent Directoy listing
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/.]+)$ description.php?id=$1 [QSA]
</IfModule>
But it doesn't work.
You can use this rule:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9]+)/[^/]+/?$ /abc/description.php?id=$1 [L,QSA]
Related
My url is http://example.com/product/Braided/table-fan
And i want to rewrite like this http://example.com/Braided/table-fan
where product is my php file.
Current rules:
Options +MultiViews +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)$ product/$1/$2/$3
RewriteRule ^([0-9a-zA-Z]+)/([0-9a-zA-Z]+)$ product.php?uname=$1&pid$2
Try and use this in your root .htaccess:
RewriteEngine On
RewriteRule ^$ product/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ product/$1
This should remove product from your URL and leave you with: http://example.com/Braided/table-fan.
Make sure you clear your cache before testing this.
My current url is
http://localhost/www.zeeshan.com/user.php?name=zeeshan06
I want to display my url as
http://localhost/www.zeeshan.com/user/zeeshan06
I use the following code but it not working
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Options +FollowSymlinks
RewriteBase /
RewriteRule ^user/(.*)user.php?name=$1 [R]
Please help me to solve my problem. Thanks.
If you place this .htaccess inside the folder www.zeeshan.com:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /www.zeeshan.com/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^user/([^/]+)$ user.php?name=$1 [NC,L]
And access the URL:
http://localhost/www.zeeshan.com/user/zeeshan06
It should lead you to:
http://localhost/www.zeeshan.com/user.php?name=zeeshan06
// http://localhost/Milan_Practice/Milan_Mvc/routing.php?name=about
RewriteEngine On
Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^(GET|HEAD|POST)\ /Milan_Practice/Milan_Mvc/routing\.php\?name=([^&]+)
RewriteRule ^ /Milan_Practice/Milan_Mvc/routing/%2/%3?%4 [L,R=301]
RewriteRule ^/?Milan_Practice/Milan_Mvc/routing/([0-9]+)/(.*)$ /Milan_Practice/Milan_Mvc/routing.php?name=$1 [L,QSA]
I have the following .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^project/([0-9]+)/([a-zA-Z0-9]+)/(.+)?$ project.php?id=$1&pName=$2&urlPram=$3 [L,NC]
</IfModule>
when my url format is something like:
mysite.com/project/1/test/vw
everything works fine. But I would also like when the url is typed in the other format, to be rewritten to the first format.
i.e. When I type the url like this:
mysite.com/project.php?id=1&pName=test&urlParam=vw
I wants it to be turned into:
mysite.com/project/1/test/vw
Do I have to write another rule? or is it accomplished in some other way?
The current rewrite rule would not handle both the cases. Add the below rewrite rule as well.
RewriteEngine On
RewriteBase /mysite/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^project/([0-9]+)/([a-zA-Z0-9]+)/(.+)?$ project.php?id=$1&pName=$2&urlParam=$3&no-redir [L,NC,QSA]
RewriteCond %{QUERY_STRING} !no-redir
RewriteCond %{QUERY_STRING} (^|&)id=([^&]+)&pName=([^&]+)&urlParam=([^&]+)
RewriteRule ^project\.php$ project/%2/%3/%4? [R=301,L,NC]
You need one more external redirect rule. Use this code:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} /project\.php\?id=([^&]+)&pName=([^&]+)&urlPram=([^&\s]+) [NC]
RewriteRule ^ project/%1/%2/%3? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^project/([0-9]+)/([a-zA-Z0-9]+)/(.+)?$ project.php?id=$1&pName=$2&urlPram=$3 [L,NC,QSA]
</IfModule>
So I want to send three variables (separated by slashes) to my index.php but I can't get it working, I'm a leek with htaccess.
My base url is localhost:8888/smbo/
And I have this code which does not work:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /smbo/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)$ index.php?id=$1&idTwo=$2&idThree=$3
</IfModule>
Who can help me?
Try this code :
RewriteEngine On
RewriteBase /smbo/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ /index.php?id=$1&idTwo=$2&idThree=$3
It is possible to rewrite my url using mod_rewrite and htaccess where a user could enter:
http://www.mainsite.com/12345
which the server would translate as:
http://www.mainsite.com/index.php?ID=12345
By also trying to remove the file extension from all pages, (remove .php) it conflicts and causes a never ending redirect:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.php$ $1 [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9a-zA-Z]+)$ index.html?ID=$1 [QSA,NC,L,R]
</IfModule>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)$ index.php?ID=$1