Reputation: 1354
I have a page in my admin system with the following path:
I am trying to rewrite it so that it directs to:
http://192.168.1.253/xxxxxx/admin/view/news-items.php?issue=3
However I cannot seem to make it work, as the page displays but the php cannot detect a $_GET variable. I have 2 .htaccess files, one in the xxxxxx directory and one in the admin directory. here they are:
xxxxxx:
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^([^/.]+)/delete/(1-9)/?$ $1.php?delete=$2 [L]
RewriteRule ^([^/.]+)/?$ $1.php [L] # rewrite without query string parameters
RewriteRule ^([^/.]+)/([^/.]+)/?$ $1.php\#$2 [L] # one name string parameter
admin:
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^([^/.]+)/?$ $1.php [L] # rewrite without query string parameters
RewriteRule ^([^/.]+)/(\d+)/?$ $1.php?id=$2 [L] # one id parameter
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/issue/(\d+)/?$ $1.php?issue=$2 [L] # one issue parameter
RewriteRule ^([^/.]+)/(\d+)/(\d+)/?$ $1.php?id=$2&file_id=$3 [L] # two parameters
Edit
Here is the new code :
xxxxxx:
RewriteEngine On # Turn on the rewriting engine
#RewriteRule ^([^/.]+)/delete/(\d+)/?$ $1.php?delete=$2 [L,QSA]
RewriteRule ^([^/.]+)/?$ $1.php [L,QSA] # rewrite without query string parameters
RewriteRule ^([^/.]+)/([^/.]+)/?$ $1.php\#$2 [L,QSA] # one name string parameter
admin:
RewriteEngine On # Turn on the rewriting engine
#RewriteRule ^([^/.]+)/?$ $1.php [L,QSA] # rewrite without query string parameters
#RewriteRule ^([^/.]+)/(\d+)/?$ $1.php?id=$2 [L,QSA] # one id parameter
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/([^/.]+)/issue/(\d+)/?$ $1.php?issue=$2 [L,QSA] # one issue parameter
RewriteRule ^([^/.]+)/(\d+)/(\d+)/?$ $1.php?id=$2&file_id=$3 [L,QSA] # two parameters
Upvotes: 0
Views: 921
Reputation:
You need to include the [QSA]
flag in your rewrite rules:
RewriteRule ^([^/.]+)/delete/(1-9)/?$ $1.php?delete=$2 [L,QSA]
RewriteRule ^([^/.]+)/?$ $1.php [L,QSA] # rewrite without query string parameters
# etc.
From the documentation:
Modifying the Query String
By default, the query string is passed through unchanged. You can, however, create URLs in the substitution string containing a query string part. Simply use a question mark inside the substitution string to indicate that the following text should be re-injected into the query string. When you want to erase an existing query string, end the substitution string with just a question mark. To combine new and old query strings, use the
[QSA]
flag.
Upvotes: 1