1

I have this situation:
all urls like /sport.html hide the real url /archive.php?action=search&section=sport

#This is the RULE:
RewriteRule ^([a-zA-Z_]+([a-zA-Z0-9_]+)?)(-([0-9]+))?\.html$ /archive.php?action=search&section=$1 [L]

Now I want to hide the real url and all direct access to the page archive.php but I receive the redirect loop error with this rule:

RewriteRule ^archive\.php.*$ /404.html [F,NC,L]
Sumurai8
  • 20,333
  • 11
  • 66
  • 100
Gennaro
  • 13
  • 1
  • 4
  • thank you I resolved used both suggestions: #THIS NOT MATCH 404 PAGE RewriteCond %{REQUEST_URI} !^404\.html$ RewriteRule ^([a-zA-Z_]+([a-zA-Z0-9_]+)?)(-([0-9]+))?\.html$ /archive.php?action=search&section=$1 [L] #THIS REDIRECT DIRECT ACCESS TO 404 RewriteCond %{THE_REQUEST} \ /archive\.php.* RewriteRule ^ /404.html? [R=301,L] – Gennaro Oct 19 '13 at 00:01

3 Answers3

1

You'll have to make sure your first rule doesn't match 404.html. You can use RewriteCond for that. See the documentation for more information about that.

RewriteCond %{REQUEST_URI} !^404\.html$
RewriteRule ^([a-zA-Z_]+([a-zA-Z0-9_]+)?)(-([0-9]+))?\.html$ /archive.php?action=search&section=$1 [L]
Sumurai8
  • 20,333
  • 11
  • 66
  • 100
  • Please note that this fixes the internal server error, but it doesn't 'hide' the real url. You'll need a redirect for that. You can find out how to do that properly [here](http://stackoverflow.com/questions/18030491/redirect-one-url-to-another-url-using-htaccess/18030624#18030624) or [here](http://stackoverflow.com/questions/19067377/user-id-dynamic-pages-htaccess/19067462#19067462). – Sumurai8 Oct 18 '13 at 16:29
1

I think what you're actually looking for isn't this:

RewriteRule ^archive\.php.*$ /404.html [F,NC,L]

As obviously, this causes a loop, since your first rule is rewriting to archive.php, and this rule rewrites it to something else, etc. etc.

Try this instead of the above rule:

RewriteCond %{THE_REQUEST} \ /archive\.php
RewriteRule ^ /404.html [F,L]

Or, if you want to be fancy about it:

RewriteCond %{THE_REQUEST} \ /archive\.php\?action=search&section=([^&\ ]+)
RewriteRule ^ /%1.html [R,L]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
0

Basically this is impossible to hide real file because of Apache' system.

But in your archive.php, you can test the current URL and redirect it to sport.html if this is not "sports.html".