简体   繁体   English

mod_rewrite-添加中间层目录

[英]mod_rewrite - add middle tier directory

Pages are currently available at the following addresses: 当前在以下地址提供页面:

http://www.domain.co.uk/solutions/article/page-name1
http://www.domain.co.uk/solutions/article/page-name2
http://www.domain.co.uk/solutions/article/page-name3
etc

..but I would like them to be accessible via the following addresses in order for enhanced SEO: ..但我希望可以通过以下地址访问它们,以增强SEO:

http://www.domain.co.uk/solutions/page-name1
http://www.domain.co.uk/solutions/page-name2
http://www.domain.co.uk/solutions/page-name3

So, I think I want to use mod_rewrite in the .htaccess file of the site root to add the 'article' directory after the solutions directory on each incoming page request. 因此,我想我想在站点根目录的.htaccess文件中使用mod_rewrite在每个传入页面请求的解决方案目录之后添加“文章”目录。 I have been looking for a suitable answer for about a month and I've tried learning the mod_rewrite basics tutorials but I just can't make this work for me so apologies for another mod_rewrite question. 我一直在寻找一个合适的答案大约一个月,并且尝试学习mod_rewrite基础教程,但是我无法为我完成此工作,因此对另一个mod_rewrite问题表示歉意。

This is my .htaccess file at present: 这是我目前的.htaccess文件:

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Removes index.php
    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]

    # If 404s, "No Input File" or every URL returns the same thing
    # make it /index.php?/$1 above (add the question mark)      
</IfModule>

I'm doing something similar on a site of mine. 我正在我的网站上做类似的事情。 Here's the .htaccess rules I'm using to remove index.php and show the shortened url: 这是我用来删除index.php并显示缩短的url的.htaccess规则:

RewriteEngine On

# Removes index.php
RewriteCond $1 !\.(css|js|gif|jpe?g|png|ico) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1

RewriteCond %{REQUEST_URI} ^/solutions/(.*) [NC]
RewriteRule ^(.*) /solutions/article/%1 [L]

Remember that the URL you see in your browser's address bar is not the URL that ExpressionEngine sees - EE sees {segment_2} as "article". 请记住,您在浏览器的地址栏中看到的URL并非ExpressionEngine看到的URL-EE将{segment_2}视为“文章”。

Edit : 编辑:

Try this : 尝试这个 :

<IfModule mod_rewrite.c>
RewriteEngine On 

RewriteCond %{REQUEST_URI} !^solutions/article/ 
RewriteRule ^solutions/(.*)$ /solutions/article/$1 [L,QSA] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !\.(gif|jpe?g|png)$ [NC] 
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM