如何编写htaccess文件,更改URL

时间:2014-12-15 05:53:06

标签: php wordpress .htaccess codeigniter

我正在尝试将实际网址转换为用户友好的动态菜单,当用户点击页面时,原始网址会变为

http://example.com/single.php?name=mypagename

我想将其更改为

http://example.com/page/mypagename

这是我的htaccess文件,我尝试从不同的角度请任何人帮助纠正它..

# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymlinks -Multiviews
Options +SymLinksIfOwnerMatch -Multiviews
RewriteEngine on
RewriteBase /

RewriteCond %{THE_REQUEST} ^(GET|HEAD|POST)\ /single\.php(\?|\ )
RewriteCond %{QUERY_STRING} name=(.+)
RewriteRule page/(.*) single.php?name=$1
RewriteRule ^ /page/%1? [L,R=301]

3 个答案:

答案 0 :(得分:1)

您必须重新安排指令:

# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymlinks -Multiviews
Options +SymLinksIfOwnerMatch -Multiviews
RewriteEngine on
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+single\.php\?name=([^\s&]+) [NC]
RewriteRule ^ /page/%1? [L,R=301]

RewriteRule ^page/(.*)$ single.php?name=$1 [L,NC,QSA]

RewriteCond %{THE_REQUEST} \s/+(Web/2015/wessexcars)/internalpage\.php?seo=\?name=([^\s&]+) [NC]
RewriteRule ^ %1/%2? [L,R=301]

RewriteRule ^(Web/2015/wessexcars)/(.+?)/?$ $1/internalpage.php?seo=$1 [L,NC,QSA]

答案 1 :(得分:0)

尝试下风,

RewriteEngine on    
RewriteRule ^/page/([a-zA-Z-0-9-]+)$ $1/single.php?name=$2 [NC]

答案 2 :(得分:0)

首先将您的配置文件更改为索引文件空白

$config['index_page'] = '';

并制作一个htaccess文件

    <ifmodule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{REQUEST_URI} ^system.*
        RewriteRule ^(.*)$ /index.php/$1 [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php/$1 [L]
    </ifmodule>