The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> .htaccess: rewrite urls to root index.php
joyful
post 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!
--
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
jimlongo
post 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
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 28th March 2024 - 04:49 AM