[英]Removing .php from URL Apache
My site directory structure as follows: 我的网站目录结构如下:
/var/www/html/wordpress/
/var/www/html/rail/
/wordpress/
is my default site when www.example.com
is accessed. 访问
www.example.com
时, /wordpress/
是我的默认网站。 Wordpress contains .htaccess
automatically made by wp. WordPress包含wp自动创建的
.htaccess
。
/rail/
is an alias inside apache sites-enabled
and is accessible at www.example.com/rail
/rail/
是sites-enabled
Apache sites-enabled
的别名,可从www.example.com/rail
访问
File contents inside /rail/
have file extension .php
, but this is shown in the address bar which I do not want, for user experience purposes. /rail/
文件内容具有文件扩展名.php
,但是出于用户体验的目的,此地址显示在我不想要的地址栏中。 I would like /rail/search/(future)/search/parameters/
Instead of /rail/search.php/future/search/parameters/
我想要
/rail/search/(future)/search/parameters/
而不是/rail/search.php/future/search/parameters/
I have read other stack overflow support topics about nanoing the .htaccess
but my htaccess
is inside wordpress
. 我已经阅读了有关
.htaccess
纳米化的其他堆栈溢出支持主题,但是我的htaccess
位于wordpress
。 Will I need to create another .htaccess inside /rail/? 我需要在/ rail /内创建另一个.htaccess吗?
What would be the best way to remove .php
file exension
from .php files, so that my URL structure is seamless, like wordpress, and not get the awkward .php? 从.php文件中删除
.php
文件exension
的最佳方法是什么,这样我的URL结构是无缝的,就像wordpress一样,而不会得到笨拙的.php? Thanks in advance. 提前致谢。
There are few changes made in you VirtualHost(apache) file, where in you where using an alias. 在您的VirtualHost(apache)文件中以及使用别名的位置中,所做的更改很少。
DocumentRoot /var/www/html/wordpress
Alias /rail "/var/www/html/rail"
<Directory "/var/www/html/rail">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>
Use the following code to remove .php extension from url for /rail/
directory by creating .htaccess file in /rail/
directory. 使用以下代码通过在
/rail/
目录中创建.htaccess文件,从/rail/
目录的URL中删除.php扩展名。
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /rail/
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.