Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
543 views
in Technique[技术] by (71.8m points)

.htaccess - Remove .php extension from url

I am required to remove .php extension and query string as well from url by rewriting the url I know this can be done in .htaccess file I have this in my .htaccess file so far

            RewriteEngine on
            DirectoryIndex Home.html

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

            # if a directory or a file exists, use it directly
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            # otherwise forward it to index.html
            RewriteRule .* Home.html

now the url example.com/blog.php?post=12&comment=3 can be accessed by example.com/blog.php/post/12/comment/3 but i want to remove .php extension as well this must be accessible through this url example.com/blog/post/13/comment/3

Any help?

Thank you in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Searches for everything except . after /

RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...