Adan Sandoval Adan Sandoval - 9 months ago 89
Apache Configuration Question

RewiteRule not working in .htaccess

I'm making a website in PHP and I've got to the part where I need to make a news page.
I have already written the

news.php
file and it uses
GET
to read the particular title of the article to display. That means I end up with an URL like

/community/news.php?title=post-title


And I much rather it to be like

/community/news/post-title


So I looked it up and saw I could do it with the .htaccess file.

Now, my actual .htaccess file looks exactly like this

ErrorDocument 404 /notfound.php

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /

# /community/news/post-title -> /community/news.php?title=post-title
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^community/news/([^/]*)$ /community/news.php?title=$1 [L]

</IfModule>


And he result of going to
/community/news/post-title
it's an 404 Error

Thank you so much for your help.

Answer Source

Thanks a lot for your help.

Turns out it was an issue with relative paths. It worked with:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /

# /community/news/post-title -> /community/news.php?title=post-title
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/community/news/([^/]*)$ community/news.php?title=$1 [L]

</IfModule>

(the difference is in the '/'s of the last line)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download