.htaccess: rewrite urls to root index.php |
.htaccess: rewrite urls to root index.php |
joyful |
Mar 26 2014, 10:15 PM
Post
#1
|
Advanced Member Group: Members Posts: 239 Joined: 15-November 10 Member No.: 13,147 |
Hello,
I am trying to rewrite/redirect all url requests for index.php files that are not in the root directory back to the root index.php file with the path as a GET variable. Here is an example: CODE http://example.com/long/path/index.php becomes: http://example.com/?path=long/path/ Here is what I have so far in my .htaccess file: CODE #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] The problem I am having is that when a url has variables, the variables get cut off. For example: CODE http://example.com/long/path/index.php?var=test becomes: http://example.com/?=long/path/index.php (the GET variable is lost) I realize this is because of the ^(.*/)$ regex. How can I keep the path's variables (ideally encoded)? Sorry, I am new to URL rewriting. Thanks in advance! -- |
jimlongo |
Mar 27 2014, 11:01 AM
Post
#2
|
This is My Life Group: Members Posts: 1,128 Joined: 24-August 06 From: t-dot Member No.: 16 |
try stackoverflow.com
|
Lo-Fi Version | Time is now: 26th September 2024 - 03:52 PM |