Вопрос

Here is my .htaccess code:

#Rewrite settings
Options +FollowSymlinks
RewriteEngine on

#Remove index.php from url
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
RewriteRule ^ /%1 [R=301,L]

#Add trailing slash
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /$1/ [L,R=301]

#Make entire url variable
RewriteRule ^(.*/)$ /index.php?path=$1 [R=301]

I would like to redirect all requests for files name "index.php" in any of the sub directories to the root "index.php" with the path as a get variable. So:

http://mywebsite.com/this/is/the/path/index.php
becomes:
http://mywebsite.com/index.php?path=this/is/the/path/

This currently works. However, the problem is that if the original url has GET variables in it, they are removed and not included in the path. So:

http://mywebsite.com/this/is/the/path/index.php?get=variables
should become:
http://mywebsite.com/index.php?path=this/is/the/path/%3Fget%3Dvariables

How can this be done? I am new to URL rewriting and can't seem to get my code to behave in this way.

Thanks for your help.

Это было полезно?

Решение

You just need to add query string append (QSA) flag like this:

RewriteRule ^(.*/)$ /index.php?path=$1 [R=301,QSA]
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top