如何使用htaccess从url中删除.php扩展名?

时间:2017-04-28 10:22:29

标签: php .htaccess

如何删除php扩展我的网址和问号替换为斜杠

http://eeroju.in/telugu/post.php?post_id=348 

http://eeroju.in/telugu/post/post_id/348 

我正在使用以下代码

        RewriteEngine On

        # Unless directory, remove trailing slash
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^([^/]+)/$ http://localhost/telugu/$1 [R=301,L]

        # Redirect external .php requests to extensionless url
        RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
        RewriteRule ^(.+)\.php$ http://localhost/telugu/$1 [R=301,L]

        # Resolve .php file for extensionless php urls
        RewriteRule ^([^/.]+)$ $1.php [L]
        ---
        <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteRule ^route-page\.php$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /route-page.php [L]
        </IfModule>

2 个答案:

答案 0 :(得分:2)

在.htaccess代码中包含此内容  **

<a href="next-page">Click here</a> to go to next page

** 在您的HTML代码中,要链接到另一个页面,请执行此操作

   popupWindow.showAsDropDown(v);

下一页是.php文件,但可以在没有.php扩展名的浏览器上呈现。

答案 1 :(得分:0)

尝试添加以下设置

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.php [NC,L]