as I'm new to mod_rewrite I'd like someone to check my code as I'm not sure of it and one part is not working as intended (description below the code)
- Code: Select all
# Redirect
Redirect 301 /panel http://panel.localhost.pl
Redirect 301 /forum http://forum.localhost.pl
Redirect 301 /wiadomosci http://wiadomosci.localhost.pl
IndexIgnore *
Options All
Options +FollowSymLinks -Indexes
RewriteEngine On
# WWW Remove
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule .* http://%1%{REQUEST_URI} [R=301,L]
# Remove index.php
RewriteCond %{THE_REQUEST} \ /(.+/)?index\.php(\?.*)?\ [NC,OR]
RewriteCond %{THE_REQUEST} \ /(.+/)?index\.php(\/.*)?\ [NC]
RewriteRule ^(.+/)?index\.php$ /$1 [NC,R=301,L]
# Rewrite all to index.php
# Ignore existing files.
RewriteCond %{SCRIPT_FILENAME} -f [OR]
# Ignore existing directories.
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule . - [PT,L]
RewriteRule .* /index\.php [QSA,L]
Now, the problem is in removing index.php. For example:
OK - http ://localhost.pl/index.php?var=val to http ://localhost.pl/?var=val
BAD - http ://localhost.pl/index.php/val1/val2 does not removing the index.php
And I'm not sure about the last rule and rewrite - the one that is rewriting everything (except existing folders and files) to index.php
for example:
http ://localhost.pl/news/50/3
is rewriting to index.php but without redirect so the adres is still visible in the browser and I'm dealing with all the variables in php by $_SERVER.
Cheers,
Sam
P.S.
Sorry for probably my poor english