Url rewriting doesn't seem to work.
I want to rewrite http://www.domain.com/files.php?key=file&id=10 to file/10
So this is the code I wrote in my .htaccess file:
RewriteEngine On
ReWriteRule ^(.*?) files.php?key=$1&id=$2
Doesn't seem to work. Anyone having a idea why?
You need two groups to use $2. Try
RewriteEngine On
ReWriteRule ^([^/]+)/(\d+)/? files.php?key=$1&id=$2
[^/]+ Means one or more symbols each of them isn't slash
Try:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([a-zA-Z]+)/([0-9]+)/$ files.php?key=$1&id=$2
Related
I need to rewrite this:
http://example.com/new/location/
to:
http://example.com/new.php?p=location
Btw it could be anything after new/ for example i need:
http://example.com/new/anything
to actually be:
http://example.com/new.php?p=anything
But i need to keep the URL structure with the slashes for SEO and security purposes
How could i achieve this using .htaccess?
currently in my htaccess ive got:
RewriteEngine on
RewriteBase /dir/
Thanks
Add the following directive into your .htaccess:
RewriteRule ^new/location$ new.php?p=location [L]
or to work any values use:
RewriteRule ^new/(.*)$ new.php?p=$1 [L]
I am not able to customize a url using .htaccess. I applied all changes in .htaccess but this one stuck with me for long time.
I have a URL :
product.php?act=pro&cat=1&category=Nokia
I want to change it to:
product/1/Nokia.html
I used following rule:
RewriteRule ^product/?([a-zA-Z_]+)/([a-zA-Z_]+)\.html$ product.php?act=$1&cat=$2&category=$3 [QSA]
But not getting this one correct.
You're capturing only 2 groups and using $1, $2, $3.
Change your code to this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^product/([^/]+)/([^.]+)\.html$ /product.php?act=pro&cat=$1&category=$2 [QSA,L,NC]
Try this:
RewriteRule ^/product/([0-9]+)/(.*).html$ ^/product.php?act=pro&cat=$1&category=$2 [NC,L]
Pattern that matches cat should have 0-9 in it
I managed to rewrite mydomain.com/file.php?id=## to this:
mydomain.com/##-Report_TITLE_OF_REPORT_HERE
by letting the .htaccess just take the ## and ignore anything that comes after it. I would like to change it to this:
mydomain.com/report-##/TITLE_OF_REPORT_HERE
However I cannot manage to wrap my head around it nor can I find any tutorial for this specific case online. The slash in the middle seems to muck everything up.
Could anyone tell me how to do this?
Try this:
RewriteRule ^report-(.*)/(.*)$ mydomain.com/file.php?id=$1 [L]
You can use this code:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^report-([^/]+)/ file.php?id=$1 [L,NC,QSA]
I have the following format:
http://www.mydomain.com/view/product/ID/CAT/TITLE
ID and CAT are both numeric. So, some real examples:
http://www.mydomain.com/view/product/1/2/ipod
http://www.mydomain.com/view/product/3/4/40-inch-tv
etc
I want to know if I should try to use mod rewrite, and how, or if I should rather fix the PHP to handle the paths correctly. I want to map the above to something like:
http://www.mydomain.com/CATEGORY/SUB_CATEGORY/TITLE
Any ideas?
RewriteEngine on
RewriteBase /
RewriteRule ^([A-Za-z0-9]+)$ /$1/ [R]
RewriteRule ^([A-Za-z0-9]+)$ index.php?cat=$1
RewriteRule ^([A-Za-z0-9]+)/([A-Za-z0-9]+)$ /$1/$2/ [R]
RewriteRule ^([A-Za-z0-9]+)/([A-Za-z0-9]+)$ index.php?cat=$1&subcat=$2
RewriteRule ^([A-Za-z0-9]+)/([A-Za-z0-9]+)/([A-Za-z0-9]+)$ /$1/$2/$3/ [R]
RewriteRule ^([A-Za-z0-9]+)/([A-Za-z0-9]+)/([A-Za-z0-9]+)$ index.php?cat=$1&subcat=$2&title=$3
in php you can get the variables as you would normally do, also you will need a rule for all variables entered and/or only category or sub-category or you will end up with a 404 when someone tries to access those pages
I would say that your question is not totally clear to me. Going by your examples what do you want your target URL to become from http://www.mydomain.com/view/product/1/2/ipod.
Will it be: http://www.mydomain.com/2/1/ipod ?
If yes then enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^view/product/([0-9]+)/([0-9]+)/(.*)$ $2/$1/$3 [L,R,NC]
I need to change
http://localhost/engineering/management/administrator/modules/course/view.php
to
http://localhost/engineering/course_view.php
using htaccess
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)_(.*)\.php$ management/administrator/modules/$1/$2.php
RewriteRule ^(.*)_(.*)\.php$ management/user/modules/$1/$2.php
Works fine for this,
But for the below url its not working
http://localhost/engineering/management/user/modules/data/edit.php
Please try with this code:-
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)_(.*)\.php$ management/administrator/modules/$1/$2.php
RewriteRule ^(.*)_(.*)\.php$ management/user/modules/$1/$2.php
Hope it helps.
when you use this one!
RewriteRule (.*)_(.*)\.php management/administrator/modules/$1/$2.php
because it's possile ro rewrite other URLs(that you've mentioned), you can add special part to it to avoid such thing. e.g:
RewriteRule swd(.*)_(.*)\.php management/administrator/modules/$1/$2.php
and url:
http://localhost/engineering/swdcourse_view.php
and for second one, use other characters than swd!!
RewriteRule ^usr(.*)_(.*)\.php$ management/user/modules/$1/$2.php