0

we have a new site in a new directory in public_html as shown in below with yellow. We need to add rules to new_site/.htaccess to fulfill the following three rules:

  1. Removing .php from the end of URLs
  2. Force trailing slash / at the end of most urls (excluding .jpg, .png, ...)
  3. Removing /index.php? from the middle of various URLs.

enter image description here

Most probably, this would be what I tried to ask:

Currently,

domain.com/ns/abc.php
domain.com/ns/abc_abc.php
domain.com/ns/index.php?/abc
domain.com/ns/abc/index.php?/abc
domain.com/ns/abc/abc/index.php?/abc/123
domain.com/ns/abc/abc/index.php?/abc/abc/123/123

To

domain.com/ns/abc/
domain.com/ns/abc_abc/
domain.com/ns/abc/
domain.com/ns/abc/abc/
domain.com/ns/abc/abc/abc/123/
domain.com/ns/abc/abc/abc/abc/123/123/

We have also tried some previously posted rules to do this task. Such as

Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /ns

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

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

The above code helped us and removed index.php. However, we could not figure it out how to remove /index.php?.

Any comment/advice is appreciated! Thanks!

1
  • 1
    Pretty URL #1 and #3 are same but they are supporting different URLs, that cannot really happen. Commented Mar 30, 2014 at 17:50

1 Answer 1

1

The following should allow you to achieve this:

RewriteEngine On
RewriteRule ^ns/(.*)/(.*)/index.php/(.*)/(.*)/(.*)/(.*)$ /ns/$1/$2/$3/$4/$5/$6/ [R,L]
RewriteRule ^ns/(.*)/(.*)/index.php/(.*)/(.*)$ /ns/$1/$2/$3/$4/ [R,L]
RewriteRule ^ns/(.*)/index.php/(.*)$ /ns/$1/$2/ [R,L]
RewriteRule ^ns/index.php/(.*)$ /ns/$1/ [R,L]
RewriteRule ^ns/(.*).php$ /ns/$1/ [R,L]

EDIT: Second try:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /ns/(.*)/(.*)/index\.php\?/(.*)\ HTTP
RewriteRule ^ /ns/%2/%3/%4\? [R,L]
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /ns/(.*)/index\.php\?/(.*)\ HTTP
RewriteRule ^ /ns/%2/%3\? [R,L]
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /ns/index\.php\?/(.*)\ HTTP
RewriteRule ^ /ns/%2\? [R,L]
RewriteRule ^ns/(.*).php$ /ns/$1/ [R,L]
Sign up to request clarification or add additional context in comments.

7 Comments

thanks for your answer! I tried it and it didn't work. Actually, there is also a ? after index.php and I tried with that too, and didnt work. Thanks again! @Howlin
You do need RewriteEngine On at the start of the htaccess file. s for the index.php? I missed that. I'll try and edit if I can add that.
Yes, I have RewriteEngine On! @Howlin
Does it at least remove the .php from the abc.php file? Also what causes there to be a ? in index.php
Not sure @Howlin ! Its a CMS we are trying to use. If you have time, you can see it here in this link It seems to me in the config files they are using index.php? Also, still could not remove .php
|

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.