Reputation: 483
I have a page called about.php inside a folder called 'pages'.
I successfully removed the .php and the directory from the url, but now the page isn't opening.
All my files are inside localhost/test/ folder. so everything used to open normally as localhost/test/pages/about.php now it shows localhost/test/about and doesn't open.
RewriteBase /test/
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
RewriteRule ^ /%1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
RewriteRule ^pages/(.*)$ $1 [L,NC,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/?$ $1.php [L]
Upvotes: 1
Views: 54
Reputation: 785276
You can use:
RewriteEngine On
RewriteBase /test/
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L,NE]
RewriteCond %{THE_REQUEST} /pages/ [NC]
RewriteRule ^pages/(.+)$ $1 [L,NC,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/pages%{REQUEST_URI}\.php -f [NC]
RewriteRule ^([^/]+)/?$ pages/$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI}\.php -f [NC]
RewriteRule ^([^/]+)/?$ $1.php [L]
Upvotes: 0