字preSS htaccess的如何删除所有的php扩展,除了index.php文件 [英] wordpress htaccess how to remove all the php extension except index.php
问题描述
我有一个字preSS博客,我想添加一些自定义的页面,并删除的.php
延伸和查询字符串的网址。
所有Word preSS页面的网址都是这样的index.php?网页名=
,所以如果我尝试添加重写规则^(。*) $ $ 1.PHP
在的.htaccess
文件时,其他页面返回 500内部服务器错误
。如何删除PHP扩展的一切,除了的index.php
和的login.php
?
下面是我现有的的.htaccess
文件:
#BEGIN字preSS
< IfModule mod_rewrite.c>
RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则。的index.php [L]
#重写规则^(。*)$ $ 1.PHP#添加此行将打破了字preSS重写规则
< / IfModule>
#结束字preSS
如果你想加入,例如,一些自定义的PHP页面,你应该添加自己的重写标准的Word preSS部分之前,但在的RewriteBase /
。
在这里,我已经添加了几个重写能够处理内部存储在私有目录的自定义页面的自定义
。
#BEGIN字preSS
< IfModule mod_rewrite.c>
RewriteEngine叙述上
的RewriteBase /
#***启动自定义零件***
重写规则^第1页$ /custom/page1.php [L,QSA]
重写规则^第2页$ /custom/page2.php [L,QSA]
#***高端定制部分***
重写规则^指数\ .PHP $ - [L]
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则。的index.php [L]
< / IfModule>
#结束字preSS
如果你的网站可以用 http://www.example.com
,您的自定义页面都可访问使用 HTTP:// WWW .example.com的/第1页
, http://www.example.com/page2
等等...
只是几句话 [L,QSA]
:
-
→
- 如果改写比赛,立即停止重写的过程,不施加任何更多的规则 -
QSA
- 附加从原来的请求URL,以自定义页面的任何查询字符串。这意味着,调用http://www.example.com/page1?foo=bar&c=1
将在内部rewrited到/自定义/ ?page1.php中富=栏和C = 1
请注意:
- 如果您已经有一个在你的话preSS网站命名为第1页页面,此页面将被添加到重写规则自定义页面覆盖。
- 在这些Apache的httpd的指令是标准和生成的Word preSS,配置
永久设置
。我刚才添加的自定义部分。 - 您修改
永久设置
,您的的.htaccess
将被覆盖,更好,如果你改变<$(c)任何时间$ C>的.htaccess 权限使文件只读。而且,在任何情况下,保存你的.htaccess配置的副本。
在另一方面,如果你只是想有网址您的Word preSS更多的搜索引擎友好的,即没有的.php
页,不完整的查询字符串,但只有网址在文章/页面塞作为唯一的标识符,您可以访问到字preSS永久设置
,然后选择帖子名称
或者选择你preFER:
当您激活永久设置
,Apache的httpd的工作仅限于htaccess的一部分。这意味着阿帕奇重定向通过htaccess的一切(请求头和身体)的index.php页面和Word preSS内部实现每一个重写。
如果你想与字preSS配置的建议,我会建议写您的问题 HTTP://字press.stackexchange.com /
I have a WordPress blog and I want to add some custom page in it and remove the .php
extension and querystring from urls.
All WordPress page urls are like index.php?pagename=
, so if I tried add RewriteRule ^(.*)$ $1.php
in the .htaccess
file, the other pages return 500 internal server error
. How can I remove the php extension from everything except index.php
and login.php
?
Here is my existing .htaccess
file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# RewriteRule ^(.*)$ $1.php # add this line will broken the wordpress rewrite rule
</IfModule>
# END WordPress
If you want add, for example, few custom php pages, you should add your own rewrites before standard Wordpress part, but after RewriteBase /
.
Here I have added a couple of rewrites able to handle custom pages stored inside in a private directory custom
.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# *** START CUSTOM PART ***
RewriteRule ^page1$ /custom/page1.php [L,QSA]
RewriteRule ^page2$ /custom/page2.php [L,QSA]
# *** END CUSTOM PART ***
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
If your site is available on http://www.example.com
, your custom pages will be accessible using http://www.example.com/page1
, http://www.example.com/page2
and so on...
Just few words regarding rewrite flags [L,QSA]
:
L
- If rewrite match, stop the rewriting process immediately and don't apply any more rules.QSA
- Appends any query string from the original request URL to custom pages. It means that callinghttp://www.example.com/page1?foo=bar&c=1
will be rewrited internally into/custom/page1.php?foo=bar&c=1
Please note:
- if you already have a page named "page1" in your wordpress site, this page will be overridden by custom page added into rewrite rule.
- These Apache httpd directives were standard and generated by Wordpress, configuring
Permalink Settings
. I have just added the custom part. - Any time you change
Permalink Settings
, your.htaccess
will be overwritten, better if you change.htaccess
permission making the file readonly. And, in any case, save a copy of your .htaccess configuration.
On the other hand if you only want your Wordpress having URLs more SEO friendly, i.e. URLs without .php
pages and without the full query strings but only the post/page slug as unique identifier, you may access to Wordpress Permalink Settings
and select Post name
or the option you prefer:
When you activate Permalink Settings
, Apache httpd work is limited to the .htaccess part. This means that Apache redirects everything (request header and body) via .htaccess to the index.php page and Wordpress implements internally every rewrite.
In case you want more suggestions related to Wordpress configuration, I'll suggest to write your questions in http://wordpress.stackexchange.com/
这篇关于字preSS htaccess的如何删除所有的php扩展,除了index.php文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!