2

How can I make both rewrites work like http://example.com/something.html http://example.com/videos/something/1.html it always matches the download.php one but not the video.php.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 
RewriteBase /
RewriteRule ^category/(.+)$ category.php?q=$1
RewriteRule ^videos/(.+)/(.+).html$ video.php?q=$1&page=$2 
RewriteRule ^(.+).html$ download.php?id=$1

2 Answers 2

2

You can have these rules as:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L,NE] 

# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^category/(.+)$ category.php?q=$1 [L,QSA,NC]

RewriteRule ^videos/([^/]+)/([^/.]+)\.html$ video.php?q=$1&page=$2 [L,QSA,NC]

RewriteRule ^(.+)\.html$ download.php?id=$1 [L,QSA,NC]
3
  • 2
    Like for the skip files section. Jan 22, 2015 at 14:50
  • Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator at webmaster@ to inform them of the time this error occurred, and the actions you performed just before this error. More information about this error may be available in the server error log. Jan 22, 2015 at 14:56
  • For which exact URL you're getting this 500 error? I have tested this on my Apache and didn't find any error.
    – anubhava
    Jan 22, 2015 at 15:02
1

Try this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 
RewriteBase /
RewriteRule ^category/(.+)$ category.php?q=$1
RewriteRule ^videos/(.+?)/(.+?).html$ video.php?q=$1&page=$2 
RewriteRule ^(.+).html$ download.php?id=$1

+ is a greedy operator. This is why download.php was always matched.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.