【问题标题】:How can I change the URL of a php page with apache [duplicate]如何使用 apache 更改 php 页面的 URL [重复]
【发布时间】:2014-02-02 00:22:30
【问题描述】:

我想例如做这个:

原始网址:domain.com/folder/index.php?i=something

更改后的网址:domain.com/folder/something

但是保留原始URL的内容,用apache的RewriteRule。谁能告诉我一个很好的教程或如何使用它的文档?

【问题讨论】:

标签: php apache


【解决方案1】:
# Open The RewriteEngine 
RewriteEngine On

RewriteBase /

# Rewrite 

RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^bbs/test-([0-9]+)\.html$ bbs/test.php?id=$1&%1

RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^jingdian-([0-9]+)\.html$ jingdian.php?id=$1&%1

【讨论】:

  • 你的答案完全错误
【解决方案2】:

正常打开httph.conf:#LoadModule rewrite_module modules/mod_rewrite.so,然后取消选中# (LoadModule rewrite_module modules/mod_rewrite.so) 创建 .htaccess 文件

RewriteEngine on
RewriteRule ^folder/([a-zA-Z0-9_-]+)/([0-9]+).html$ index.php?id=$2

RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule (.*) /folder/$1

你配置错误 ErrorDocument 错误代码 /error.html 示例:ErrorDocument 404/error_404.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-17
    • 1970-01-01
    • 1970-01-01
    • 2014-01-23
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    • 2023-03-05
    相关资源
    最近更新 更多