Php .htaccess中的更改文件url被卡住
我是.htaccess文件中的新手,所以我想更改每个文件的不同URL。默认情况下,我只对1个文件使用此URL 然后我改变我的contactus.php文件URL,然后我在下面的谷歌上这样做Php .htaccess中的更改文件url被卡住,php,.htaccess,mod-rewrite,url-rewriting,rewrite,Php,.htaccess,Mod Rewrite,Url Rewriting,Rewrite,我是.htaccess文件中的新手,所以我想更改每个文件的不同URL。默认情况下,我只对1个文件使用此URL 然后我改变我的contactus.php文件URL,然后我在下面的谷歌上这样做 它不工作的一些方法,我更多的尝试,但整个网站不工作。如何根据需要更改每个文件的不同URL。请尝试以下隐藏.php的代码 Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / ## do
它不工作的一些方法,我更多的尝试,但整个网站不工作。如何根据需要更改每个文件的不同URL。请尝试以下隐藏.php的代码
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## don't touch /forum URIs
RewriteRule ^forums/ - [L,NC]
## hide .php extension snippet
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
或
参考链接
我们可以使用.htaccess文件重写URL。但在将某些内容写入.htaccess文件之前,我们需要验证使用的是哪种服务器。在本例中,您可以使用apache服务器或Nginx服务器。只需添加一个
<?php phpinfo(); ?>
重写规则
在某些情况下,您可能只有几个页面,您可以在.htaccess文件中指定网站中的每个页面。在这种情况下,您可以使用这种重写
比如说
重写规则^article/used/to/be/here.php$/article/now/lifes/here/[R=301,L]
假设您必须像这样重写url
http://en.wikipedia.org/wiki/url_rewriting
您应该在.htaccess文件中编写类似的内容
RewriteEngine On
RewriteRule ^wiki/(.+)$ w/index.php?title=$1 [L]
但页面的实际实现将如下所示
http://en.wikipedia.org/wiki/url_rewriting
重写秒
这可用于根据某些条件重写某些url。假设您需要使用您的网站名称添加或删除www,并在特定条件下重定向到特定页面,如url不可用或错误消息
例如:
RewriteCond %{HTTP_REFERER} !^http://(www.)?example.com/.*$ [NC]
你可以在这里进一步查阅
案例2:nginx服务器
在nginx服务器上启用模块HttpRewriteModule
根据nginx设置使用location重写URL
范例
location / {
root /path/to/drupal;
index index.php index.html;
try_files $uri $uri/ @rewrite;
}
location @rewrite {
rewrite ^/(.*)$ /index.php?q=$1;
}
是否要从页面名称中删除.php扩展名?@Zeeshan yeh remove.php但不删除特定文件。aboutus.php和contactus.php我还想将类似contactus.php的url更改为Contact-Us,aboutus.php更改为关于usno工作:“当我使用您的第一个代码时,它的make错误没有找到。在每一页上。第二个代码不起作用。@user3458209检查引用链接
RewriteEngine On
RewriteRule ^wiki/(.+)$ w/index.php?title=$1 [L]
RewriteCond %{HTTP_REFERER} !^http://(www.)?example.com/.*$ [NC]
location / {
root /path/to/drupal;
index index.php index.html;
try_files $uri $uri/ @rewrite;
}
location @rewrite {
rewrite ^/(.*)$ /index.php?q=$1;
}