Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Web Server Configuration _ .htaccess: rewrite urls to root index.php

Posted by: joyful Mar 26 2014, 10:15 PM

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!
--

Posted by: jimlongo Mar 27 2014, 11:01 AM

try stackoverflow.com

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)