How can I rewrite my URL from edit.php?id=2
to edit/id/2
?
2 Answers
Try this
RewriteEngine On
RewriteBase /
RewriteRule ^edit/id/([0-9]+)/?$ edit.php?id=$1 [NC,QSA,L]
-
It works but my styles.css and other images doesn't load coz the location has changed.– cloud 9Commented Nov 14, 2011 at 3:26
-
do you have other rules? what is the URL for the style.css? Commented Nov 14, 2011 at 3:31
-
I added a variable in my includes like <?php echo $currentdir;?>/niceforms.js but niceform.js generates img/0.png and img/0.png don't load.– cloud 9Commented Nov 14, 2011 at 3:38
-
-
This should be the location of "img/0.png" in my php output.My img folder is the same location as edit.php img/0.png but the result is edit/id/img/0.png– cloud 9Commented Nov 14, 2011 at 3:45
In case you need redirect from:
http://yoursite.com/subpage1/subpage2/?YOURSTRING=blabla
---------->
http://yoursite.com/subpage1/subpage2/
then in the beginning of .htaccess
, insert:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} YOURSTRING=(.*)
RewriteRule ^(.*)$ /$1? [R=301,L]
</IfModule>
## If WordPress is not installed in root folder, then edit the fourth line like this
RewriteRule ^(.*)$ /YOUR-WORDPRESS-DIRECTORY/$1? [R=301,L]
p.s. if you want other redirection from QUESTION MARK, then use: https://stackoverflow.com/a/15680832/2377343
-
Instead of putting a link to answer the question, could you write the answer here?– j0kCommented Mar 28, 2013 at 14:38