Home Url Rewriting with hidden rules
Reply: 1

Url Rewriting with hidden rules

Julian Hardenne
1#
Julian Hardenne Published in 2017-11-10 14:27:23Z

I'm currently facing a problem with one url rewriting rule. [I'm running on Apache 2.4.23]

I'm trying to make a redirection for certain pages. Here are my rules :

RewriteRule ^clubs[^/]?$  club.php?job=display [L,NC]<br />
RewriteRule ^club/([^/]*)$   club.php?job=detail&name=$1 [L]<br />
RewriteCond %{REQUEST_URI}  !club\.php                                      [NC]<br />
RewriteRule ^club/([^/]+)/?(.+)?/?       club.php?job=detail&name=$1&action=$2           [NC,L]

The problem is that rule for "clubs" is working well. But those for club aren't working. If I go to the url http://mysite/club , I can see that it has already been rewrited to http://mysite/club.php?
And if I go to the url http://mysite/club/clubName , I can see that it has already been rewrited to http://mysite/club.php/clubName?
And all of this because the file club.php exists. If I had redirected 'club' to 'anythingElseButNonExistingFile' , it would have worked. Even if I remove all the lines in my .htaccess file, this happens. So I suppose there's another .htaccess file with other rules somewhere I do not have access to.

So I changed my rules for 'club' to :

RewriteRule ^club.php/(.+)                     club.php?job=detail&name=$1 [L]<br />
RewriteCond %{REQUEST_URI}                  !club\.php                                     [NC]<br />
RewriteRule ^club/([^/]+)/?(.+)?/?        club.php?job=detail&name=$1&action=$2          [NC,L]<br />

So now, if I try to go to :
http://mysite/club/clubName, it works, it redirects to
http://mysite/club.php/clubName?job=detail&name=clubName
Not nice but working...

But if I try to go to http://mySite/club/clubName/addPhoto, url is not properly rewritten. I get : http://club.php/clubName/addPhoto?job=detail&name=clubName%2FaddPhoto I don't know how to get rid of this...

I hope this is not too much confused and that someone will have a solution... Thanks in advance !

julp
2#
julp Reply to 2017-11-10 15:02:45Z

But those for club aren't working. If I go to the url http://mysite/club , I can see that it has already been rewrited to http://mysite/club.php?

You need to disable content negociation by Options -MultiViews in your .htaccess.

And if I go to the url http://mysite/club/clubName , I can see that it has already been rewrited to http://mysite/club.php/clubName?

This is the fault of the combination of content negociation and PathInfo feature (see AcceptPathInfo directive). The PathInfo feature allows an extra (and unexistant) path behind the file (/clubName in your example) while the content negociation internally rewrite club into club.php.

So to not be bothered when doing rewriting, it might be a good idea to eliminate both with these statements (in your .htaccess file):

Options -MultiViews
AcceptPathInfo off
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.334277 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO