0
votes

When I request

http://localhost/project/mycontroller/

the URL rewrites to

http://localhost/project/mycontroller/?l=mycontroller

The .htaccess (my guess) is concatenating the same GET variable to the URL.

Note 1 : l is actually my $_GET variable and everything works fine, even if I mess up with the non-friendly URL.

Note 2 : Firstly I thought it could be some redirecting that my framework could be doing so I put a php exit(); on the first line of the index.php and it continued to rewrite, so I thought it could be the .htaccess file.

Have any of you solved this before?

.htaccess

<Files magic>
ForceType application/x-httpd-php5
</Files>

<IfModule mod_rewrite.c>
RewriteEngine On 
Header append Vary User-Agent       

#?l=local -> /local
RewriteRule ^([a-z0-9_]+)$ ?l=$1 [NC,L]
RewriteRule ^([a-z0-9_]+)/$ ?l=$1 [NC,L]

#?l=local&sl=sublocal -> local/sublocal
RewriteRule ^([a-z0-9_]+)/([a-z0-9_]+)$ ?l=$1&sl=$2 [NC,L]
RewriteRule ^([a-z0-9_]+)/([a-z0-9_]+)/$ ?l=$1&sl=$2 [NC,L]

#?l=local&sl=sublocal&cod=1 -> local/sublocal-1
RewriteRule ^([a-z0-9_]+)/([a-z0-9_]+)/([0-9]+)$ ?l=$1&sl=$2&cod=$3 [NC,L]
RewriteRule ^([a-z0-9_]+)/([a-z0-9_]+)/([0-9]+)/$ ?l=$1&sl=$2&cod=$3 [NC,L]

#?l=local&sl=sublocal&cod=1 -> local/sublocal/var
RewriteRule ^([a-z0-9_]+)/([a-z0-9_]+)/([a-z0-9]+)$ ?l=$1&sl=$2&var=$3 [NC,L]
RewriteRule ^([a-z0-9_]+)/([a-z0-9_]+)/([a-z0-9]+)/$ ?l=$1&sl=$2&var=$3 [NC,L]

</IfModule>

Address bar:

address bar

1
What is location your .htaccess? Are there more rule or any other .htaccess any where in your system? - anubhava
The file is located on the root folder: localhost/project/.htaccess, there is another .htaccess on the admin folder: localhost/project/admin/.htaccess - melloc
ok is this full /project/.htaccess content? And is /project/mycontroller/ a real directory? - anubhava
Yes, it is the full content, and it is a real directory @anubhava - melloc
Hmm doesn't look like it pasted full content since <IfModule mod_rewrite.c> is not closed in the code above. - anubhava

1 Answers

1
votes

Try this code:

<Files magic>
ForceType application/x-httpd-php5
</Files>
Header append Vary User-Agent       
DirectorySlash off

<IfModule mod_rewrite.c>
RewriteEngine On 
RewriteBase /project/

#?l=local -> /local
RewriteRule ^(\w+)/?$ ?l=$1 [QSA,L]

#?l=local&sl=sublocal -> local/sublocal
RewriteRule ^(\w+)/(\w+)/?$ ?l=$1&sl=$2 [QSA,L]

#?l=local&sl=sublocal&cod=1 -> local/sublocal-1
RewriteRule ^(\w+)/(\w+)/(\w+)/?$ ?l=$1&sl=$2&cod=$3 [QSA,L]

#?l=local&sl=sublocal&cod=1 -> local/sublocal/var
RewriteRule ^(\w+)/(\w+)/(\w+)/?$ ?l=$1&sl=$2&var=$3 [QSA,L]

</IfModule>