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

Categories

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

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

1 Answer

Searches for everything except . after /

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...