Ashish_more
Ashish_more

Reputation: 55

Redirection Issues in htaccess

This is my .htacess in this I able to remove .php extension but it is not working as per expected output (eg. https://localhost/shap/example.php to https://localhost/shap/example) it is working for index.php but it is working for other .php page, it is been stuck in redirection please help me get resolve this issue

error getting : enter image description here

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

# Return 404 if original request is .php
# RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$"
# RewriteRule .* - [L,R=404]

RewriteRule ^index\.php$ https://localhost/shap/ [NC,R]

RewriteRule ^example\.php$ https://localhost/shap/example[R]
</IfModule>

Upvotes: 2

Views: 91

Answers (1)

RavinderSingh13
RavinderSingh13

Reputation: 133428

With your shown samples, please try following htaccess Rules file. Make sure keep htaccess file root folder(along side with example folder NOT inside example folder).

Clear your browser cache before testing your URLs.

RewriteEngine ON
RewriteBase /example/
RewriteCond %{THE_REQUEST} \s/example/example\.php\s [NC]
RewriteRule ^ /example/example? [R=301,L]

RewriteRule ^(example)/(example)?$ $1/$2.php [NC,L]

Upvotes: 3

Related Questions