Question

I am a newb to PHP. Can anyone tell me what each line does here. Do I need this? It is giving me errors

RewriteCond %{REQUEST_URI} /~([^/]+)/?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /~%1/rewrite.php?p=$1&%{QUERY_STRING} [L]
RewriteCond %{REQUEST_URI} /~([^/]+)/?
RewriteRule ^index\.php?(.*)$ /~%1/rewrite.php?p=%1&%{QUERY_STRING} [L]
#there is no ~ character in the URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) ./rewrite.php?p=$1&%{QUERY_STRING} [L]
RewriteRule ^index\.php?(.*)$ ./rewrite.php?p=$1&%{QUERY_STRING} [L]
#WJ-180 fix
RewriteRule ^resume\.php?(.*)$ ./rewrite.php?p=resume\.php$1&%{QUERY_STRING} [L]
Was it helpful?

Solution

The simple answer: These declarations rewrite every request to a rewrite.php file.

The more comprehensive answer: The RewriteCond and RewriteRule directives are from the Apache module mod_rewrite and provide a rule based URL rewrite mechanism.

It seems that these rules are intended to rewrite every request to a rewrite.php file, either in a specific directory (/~foobar/rewrite.php) or in the root (/rewrite.php).

OTHER TIPS

If you are new, please read http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html, it is explained very nicely.

p.s. Your title "What do these declarations mean in my PHP .htaccess file?" is incorrect, .htacces is not php file.

These say

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

"Only use the following rule if the request does not match an existing file or directory."

Those are mod_rewrite configuration entries.

It an Apache mod_rewrite rule. Unless you are using some sort of framework you probably don't need it. See Apache mod_rewrite for more info.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top