user8529538
user8529538

Reputation:

htaccess doesn't rewrite all rules

The .htaccess file ignores the first rule

The url should be http://example.com/public_html/folder/file.php

# Rewrite all to public_html
RewriteCond %{REQUEST_URI} !php/
RewriteRule (.*) /public_html/$1
# URL: http://example.com/public_html/folder/file

# Hide/Add .php from/to URL
RewriteCond %{DOCUMENT_ROOT}/$1 !-d
RewriteCond %{REQUEST_FILENAME} !\.(.*)
RewriteCond %{REQUEST_URI} !php/
RewriteRule (.*) $1.php
# URL: http://example.com/folder/file.php

Upvotes: 1

Views: 27

Answers (1)

anubhava
anubhava

Reputation: 785276

Have it this way inside /Users/gus/sites/New/8888/goestav5/.htaccess:

RewriteEngine On

# ignore all php/ URIs
RewriteRule ^php/ - [L,NC]

# add .php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^.]+?)/?$ $1.php [L]

# rewrite every non-file, non-directory to public_html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!public_html/)(.*)$ public_html/$1 [L,NC] 

Upvotes: 0

Related Questions