Jessica
Jessica

Reputation: 63

url rewrite to short url

Good days guys, I need your help with this url rewrite.

The are two rewrites I want to do.

1) I want to take out .php from the url even though my files is saved as .php

2) I want to rewrite the url below

If you can help me. It will be lovely. Thanks

Upvotes: 0

Views: 84

Answers (1)

anubhava
anubhava

Reputation: 785156

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]

Upvotes: 1

Related Questions