2

I've been trying to get this mod rewrite thing down. Basically I want:

  • removed.com/WineGlass/Vin.php
  • removed.com/Chandelier/Auto.php

To be translated to:

  • removed.com/news.php?post=Vin.php&cat=WineGlass
  • removed.com/news.php?post=Auto.php&cat=Chandelier

So far I have:

Options -Multiviews Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^/(.*)/(\w+.php)$ ./news.php?cat=$1&post=$2 

My understanding of what is going on is that it should be attempting to determine if the file exists and if it does not, check to see if it meets the patter. If it meets the pattern, it should rewrite the url to the one desired.

  • I use GoDaddy.com as my host and I found many posts on the internet suggesting that -Multiviews was required.
  • The exact error is: The requested URL /poz/WineGlass/Vin.php was not found on this server.
  • the root is /removed/ and that is where news.php rests
  • I used regexr.com to test the regular expression: http://regexr.com?37s5e
  • Bonus: I tried several ways to exclude the last URL in the example above but was unable to. If you can help with that, I would be very greatful.

1 Answer 1

2

Use this rule in your DOCUMENT_ROOT/.htaccess file:

Options +FollowSymLinks -Multiviews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/([^.]+\.php)$ /news.php?cat=$1&post=$2 [L,QSA] 
Sign up to request clarification or add additional context in comments.

8 Comments

I will accept the answer when it lets me as this works; however, if you could explain a little bit more indepth as the only change made appears to be the [LmQSA]
More important change than [L,QSA] is the removal of leading slash from RewriteRule. .htaccess is per directory directive and Apache strips the current directory path (thus leading slash) from RewriteRule URI pattern.
I pasted your expression into the tool and it selects all of the text. I'm fearful this might affect every url?
By putting leading slash earlier, you rule stopped matching so yes it stops 500 error but also it will stopped working :)
QSA (Query String Append) flag preserves existing query parameters while adding a new one. And L is for making a rewriterule as Last that forces Apache to re-inject resulting URI for further processing.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.