使用htaccess重写简单的url

时间:2013-11-26 15:01:09

标签: regex apache .htaccess mod-rewrite url-rewriting

如何重写

website.com/feed/file.xml 

website.com/feed 

使用htaccess?

我需要用户访问第一行并向他显示第2行的内容。

编辑1:已发布当前.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule    ^feed?$    feed/sejururi.xml    [NC,L] 
</IfModule>

2 个答案:

答案 0 :(得分:1)

  

I need the user to access first line and show him the content from 2'nd line.

此规则适合您DOCUMENT_ROOT/.htaccess文件:

RewriteEngine On  

RewriteRule ^(feed)/sejururi\.xml$ /$1 [NC,L] 

更新:完整.htaccess:

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /

RewriteRule ^(feed)/sejururi\.xml$ $1 [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>

答案 1 :(得分:0)

尝试:

RewriteEngine On  
RewriteRule    ^feed?$    feed/file.xml    [NC,L]