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
Related
I'm building a RestApi and I have a problem with urls. I want to transform "api.php?request=users" into "api/users". But I also want it to be dinamic. For example: If a user types "api/users/13" I want it to be tha same as "api.php?request=users&id=13". Is there any way to make it dinamic? Do I have to create every case individually? How could this be done in each of these two cases? Thanks so much in advance for your help!!
the best way is change .htaccess file like this:
RewriteEngine On
RewriteRule ^api/([^/])/([^/])/([^/]*)$ /api.php?request=$1&id=$2&state=$3 [L]
The original URL:
http://www.domain.com/api.php?request=mike&id=3&state=active
The rewritten URL:
http://www.domain.com/api/mike/3/active
update: if you don't know the number of parameter add one more rewrite for each 'level':
RewriteRule ^api/([^/])/([^/])/([^/])$ /api.php?request=$1 [L]
RewriteRule ^api/([^/])/([^/])/([^/])$ /api.php?request=$1&id=$2 [L]
RewriteRule ^api/([^/])/([^/])/([^/]*)$
/api.php?request=$1&id=$2&status=$3 [L]
Regards.
I think you must add a new RewriteRule, because you need different variables.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)/(.*)/?$ $1.php?request=$2
RewriteRule ^(.*)/(.*)/(.*)/?$ $1.php?request=$2&id=$3
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
I try to rewrite my SEO URLs to some real GET requests, to handle in my PHP file.
I want to have these 2 cases to work:
mysite.com/company-profile -> index.php?action=company-profile
mysite.com/faq/howcanijoin -> index.php?action=faq&anchor=howcanijoin
I got the first case to work using the rule:
RewriteRule ^([A-Za-z0-9-]+)$ index.php?action=$1
For the second I tried also. I put this rule before the previous one:
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ index.php?action=$1&anchor=$2
But it's not working. Any suggestions? If I understand correctly inside each parenthesis goes variables $1, $2 etc?
Do this
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)/(.*)$ /index.php?action=$1&anchor=$2
This?
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ index.php?action=$1&anchor=$2 [QSA,L]
the incoming URL
domain.com/12/3
should be re-written to
domain.com/?w=12&h=3
htaccess
RewriteEngine on
RewriteRule ^([a-z]{2,2})/([a-zA-Z0-9_-]+)$ index.php?w=$1&h=$2 [QSA]
the php
<?php
echo $_GET['h'];
?>
Result
404 page
I've tried using htaccess to change the result of the url and then retrieve the value from the URL, could someone help me out?
Maybe you need to escape - like:
RewriteRule ^([a-z]{2,2})/([a-zA-Z0-9_\-]+)$ index.php?w=$1&h=$2 [QSA]
PS. I hope the above URL /12/3 is just for example because your regex accepts only a-z
RewriteEngine On
RewriteRule ^[a-z]{2,2})/([a-zA-Z0-9_-]+)$ /index.php?w=$1&h=$2 [QSA]
Essentially, I'm pretty sure you need a / in front of index.php
I like to use this generator for my mod-rewrite rules.
http://www.generateit.net/mod-rewrite/
Try changing your rewriterule to the following:
RewriteEngine on
RewriteRule ^([a-z0-9]{2})/([a-zA-Z0-9_-]+)$ /index.php?w=$1&h=$2 [QSA]
Your example has two digits as the first parts of the path, which won't be matched by [a-z].
RewriteEngine On
RewriteRule ^(.*)/(.*)$ index.php?w=$1&h=$2 [QSA]
The above sorted it. Thanks for the replies
I'm trying URL re-writing for the first time and I have the following URLS which need rewriting:
http://domain.com/resorts.php?countryname=Portugal
http://domain.com/rss.php?destination=Torremolinos&itemtype=rfamily
I've written the following in my .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteRule /countryname/(.*)/ resorts.php?countryname=$1
RewriteRule /destination/(.*)/itemtype/(.*)/ rss.php?destination=$1&itemtype=$2
But when I try the following, I keep getting URL not found. Please can someone point out what I may be doing wrong? Many thanks in advance.
http://domain.com/countryname/Portugal
http://domain.com/destination/Torremolinos/itemtype/rfamily
You can use this:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule countryname/(.*)/? resorts.php?countryname=$1 [NC,L]
RewriteRule destination/(.*)/itemtype/(.*)/? rss.php?destination=$1&itemtype=$2 [NC,L]