0

I have the following working:

removes the www section from the url if used
hides the .php section from the url
hides the /parts folder eg:(happylocation.it/parts/anotherpart/this.php into happylocation.it/anotherpart/this.php)

Facts:

parts is a real folder/directory
anotherpart is a real folder/directory and has all the php files
there are no other files in <root> other then index.php
there are no files in the parts folder/directory

Folder/Directory structure:

<root>/index.php
<root>/parts/anotherpart/this.php

What .htacces I have running:

Options -Indexes
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www.happylocation.it$ [NC]
RewriteRule ^(.*)$ https://happylocation.it/$1 [R=301,L]

RewriteCond %{THE_REQUEST} \s/parts/([^\s]+)\s [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/parts/$1 -f
RewriteRule ^(.+)$ /parts/$1 [L,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

The problem is that when browsing to happylocation.it/anotherpart/this it responds with was not found on this server. What I hope to achieve is to have urls like

happylocation.it/anotherpart/this/friendlypageID

2

1 Answer 1

1

You should do this rule

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/parts/$1 -f
RewriteRule ^(.+)$ /parts/$1 [L,QSA]

like this.

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)/?$ /parts/$1 [L,QSA]
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! that worked, how come that RewriteCond %{DOCUMENT_ROOT}/parts/$1 -f messes the .php hide up?
Because it was never matching. You were saying to only process that rule if document_root/parts/anotherpart/this is a real file. Well it's not. So it will never match and the rule will not be executed. You only need to check if the URL is not a real file or not a real directory. Which the first 2 conditions do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.