I have url that I want to rewrite so it can pass the parameter like this
From www.example.com/questions.php/postid=101&title=htaccess_tuts
To www.example.com/questions.php/postid/1/title/htaccess_tuts
I have been trying to get this done using below .htaccess but i end up getting this
From www.example.com/questions.php/postid=1&title=htaccess_tuts
To www.example.com/questions.php/postid/101
The title part didn't show.
Can anyone help me pass it multiple parameter
RewriteBase /
#Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
#here is the problem i have don this but didn't work
#RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+questions\.php\?postid=([^\s&]+)&([^\s&]+) [NC]
#What can i do again?
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+questions\.php\?postid=([^\s&]+) [NC]
RewriteRule ^ questions/%1? [R=301,L]
RewriteRule ^questions/([^/]+)/?$ questions.php?postid=$1&title=$2 [L,QSA]
RewriteEngine On
RewriteRule ^questions\.php/postid/([^/]*)/title/([^/]*)$ /questions.php?postid=$1&title=$2 [L]
you can use this site for generate rewrite rules
Related
I'm trying to get a my original url which would have been properties.php?bed=1&page=1&perpage=12&area=testarea to /search/1/1/12/testarea. But the last query string 'area' is optional and so could be blank.
I have this so far below, the problem is if I add an extra ([^/]+)/ such and
RewriteRule search/([^/]+)/([^/]+)/([^/]+)/([^/]+)/? pages/properties.php?bed=$1&page=$2&perpage=$3&area=$4
and then don't supply an area in the url, it fails to work correctly. Is there a correct way to do this where the query sting can be optional?
Also another problem I'm having is I would like this
RewriteRule search-rooms/([^/]+)/([^/]+)/([^/]+)/? pages/rooms.php?bed=$1&page=$2&perpage=$3&area=$4
to be /search/rooms/ not /search-rooms/ but if I put an extra / after search it again doesn't work correctly and the page reads the wrong data from the URL.
This is the full version
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule property/([^/]+)/? pages/show.php?id=$1 [NC,L]
RewriteRule search/([^/]+)/([^/]+)/([^/]+)/? pages/properties.php?bed=$1&page=$2&perpage=$3&area=$4 [L,QSA,NC]
RewriteRule search-rooms/([^/]+)/([^/]+)/([^/]+)/? pages/rooms.php?bed=$1&page=$2&perpage=$3&area=$4 [L,QSA,NC]
RewriteCond %{HTTP_HOST} ^www.studentlettingsagency.co.uk$ [OR]
RewriteCond %{HTTP_HOST} ^studentlettingsagency.co.uk$
RewriteRule ^(.*) http://www.stla.co.uk/$1 [QSA,L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>
Any help would be great!
You can use the following rule :
RewriteCond %{REQUEST_URI} !^/search/rooms
RewriteRule search/([^/]+)/([^/]+)/([^/]+)/?([^/]*)?/?$ pages/properties.php?bed=$1&page=$2&perpage=$3&area=$4 [NC,L]
RewriteRule search/rooms/([^/]+)/([^/]+)/([^/]+)/?([^/]*)?/?$ pages/rooms.php?bed=$1&page=$2&perpage=$3&area=$4 [NC,L]
RewriteCond is important here ,as it tells the first rule not to match the uri /search/rooms
I want to include item details details.php if url has parameter id=xyz
rewrite
url www.example.com/index.php?id=xyz
to
www.example.com/xyz.html
using htaccess
htaccess i am using has
RewriteEngine On
RewriteBase /
RewriteRule ^([^.]+)\.html$ index.php?id=$1 [L,QSA,NC]
RewriteCond %{THE_REQUEST} \s/index\.php\?id=([_0-9a-zA-Z-]+)\s [NC]
RewriteRule ^%1? [R=301,L]
RewriteRule ^([_0-9a-zA-Z-]+)$ /index.php?id=$1 [L]
RewriteCond %{THE_REQUEST} \s/index\.php\?id=([_0-9a-zA-Z-]+)\s [NC]
RewriteRule ^ %1.html? [R=301,L]
RewriteRule ^([_0-9a-zA-Z-]+?)(?:\.html)?$ /index.php?id=$1 [NC,L]
worked perfect
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^([^.]+)\.html$ index.php?id=$1 [L,QSA,NC]
Use this .htaccess to rewrite:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)\.html$ index.php?id=$1 [L,QSA,NC]
</IfModule>
Make sure you have mod_rewrite enabled (use phpinfo() or apache_get_modules() in PHP if available)
Please try following configuration in your www.example.com/.htaccess file,
i just test it and work fun on my env.
//htaccess file content
RewriteEngine On
RewriteRule ^(\w+).html$ /index.php?id=$1 [L]
I have a URL like this
www.subdomain.mydomain.com/mydir/admin/index.php?page=dashboard
I want to have a user friendly url like this
www.subdomain.mydomain.com/mydir/admin/dashboard
How do I achieve this? I am trying with the below mentioned code. What am I doing wrong here?
Options -MultiViews
# URL rewriting module activation
RewriteEngine on
RewriteCond %{REQUEST_METHOD} !^(TRACE|TRACK|GET|POST|HEAD)$
RewriteRule .* - [F]
RewriteBase /
Options +FollowSymLinks
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?page=$1 [L]
For a similar context please refer this question.
Try this .htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine on
# use appropriate rewrite base
RewriteBase /mydir/admin/
RewriteCond %{REQUEST_METHOD} !^(TRACE|TRACK|GET|POST|HEAD)$
RewriteRule ^ - [F]
RewriteCond %{THE_REQUEST} /index\.php\?page=([\w-]+) [NC]
RewriteRule ^ %1? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ index.php?page=$1 [L,QSA]
Hi I am new to url rewrite help in this process.
Actually I want to rewrite my url from :
http://abcd.com/merchant.php?store=2&area=323&storename=Vendor-2
to
http://abcd.com/Vendor-2
But it's not working. When I click on href target that time it is loading. Below is my .htaccess file
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ /%1 [R=301,L]
RewriteRule ^([^/]*)\.html$ /merchant\.php?store=1&area=132&storename=$1 [L]
Above file is my .htaccess file but it's not working.
Can somebody give me a suggestion?
# This should match when storename contains [a-zA-Z0-9_-]
RewriteCond %{QUERY_STRING} storename=([\w-]+)
RewriteRule merchant.php /%1 [R=301,L]
I have an url which is http://www.urlbookmarking.com/bookmarks-details.php?bid=55
and I want it to be like
http://www.urlbookmarking.com/bookmark/55
I wrote in my htaccess:
RewriteEngine on
RewriteRule /bid/(.*) bookmarks-details.php?bid=$1
But when I go to the first URL the rewrite engine does not apply my rule. Is there any mistake, or conflict somewhere?
My full htaccess file written as follows
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^urlbookmarking.com [NC]
RewriteRule ^(.*)$ http://www.urlbookmarking.com/$1 [L,R=301]
RewriteEngine on
RewriteRule /bid/(.*) bookmarks-details.php?bid=$1
Please help me.
The line Options +FollowSymLinks is optional if already configured in httpd.conf
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^urlbookmarking\.com [NC]
RewriteRule ^(.*)$ http://www.urlbookmarking.com/$1 [R=301, L]
RewriteRule ^bookmark/([0-9]+)$ bookmarks-details.php?bid=$1 [NC, L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
A few things:
RewriteEngine On only needs to called once, though this may not be causing any problems
I also have RewriteBase / after my RewriteEngine On line
My rewrite rule looks like this: RewriteRule ^common/(.*)$ common.php?file=$1 [QSA,L], which tells me that your rule should looke like this RewriteRule ^bookmark/(.*) bookmarks-details.php?bid=$1 [QSA,L]
you should use only one RewriteEngine on
RewriteRule /bid/(.*) bookmarks-details.php?bid=$1 - put this line after Options +FollowSymLinks
Try again
Do you want you url to be /bid/55 or /bookmark/55? because you have written it as if it is going to be /bid/55...
Anyway, your .htaccess should look more like this:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^urlbookmarking.com [NC]
RewriteRule ^(.*)$ http://www.urlbookmarking.com/$1 [L,R=301]
RewriteRule ^bid/(.*)$ bookmarks-details.php?bid=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
...without the multiple RewriteEngine on directives (these don't break anything but are unnecessary), and without the leading forward slash on the bid rewrite rule. Also, put your new rule before the rules that rewrites for non-existent file so it doesn't rewrite your URL before you get a chance to use it, and add a [L] flag to the rule so it doesn't get further modified by the other rules. Also, add the line start/end markers (^/$) to the rule.
You would only use the leading forward slash if you were putting the rules in httpd.conf, you don't use them in .htaccess files.
If you want your urls to be /bookmark/, just replace bid with bookmark.
This should redirect all '/bookmarks-details.php\?bid=(id)' urls with bookmarks ids (that have only numbers) to /bookmark/(id).
RewriteRule ^/bookmarks-details\.php\?bid=([0-9]+) /bookmark/$1 [R, NC, L]
Once you successfully rewritten the URL, you then need to write a companion rule to process it, like so:
RewriteRule ^/bookmark/([0-9]+) /bookmarks-details\.php\?bid=$1 [NC, L]
If should go between the rule that always adds 'www' to the beginning and the catch all rule, which I placed at the end. All together, it may look like so:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^urlbookmarking.com [NC]
RewriteRule ^(.*)$ http://www.urlbookmarking.com/$1 [L,R=301]
RewriteRule ^/bookmarks-details\.php\?bid=([0-9]+) /bookmark/$1 [R, NC, L]
RewriteRule ^/bookmark/([0-9]+) /bookmarks-details\.php\?bid=$1 [NC, L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
This link may make things clearer: http://corz.org/serv/tricks/htaccess2.php