重写包含多个页面的网址

时间:2016-10-09 15:44:04

标签: php .htaccess mod-rewrite

我正在尝试在具有分页选项的页面上重写我的网址,而我不确定要使用哪个字符串,因为我正在使用的字符串不起作用。

我的文档结构在

下面
  • blog-listing.php
  • htaccess的
  • /blog/post.php
  • / CSS /
  • / JS /
  • /图像/

我的htaccess文件中已有的内容

RewriteEngine on
RewriteRule ^blog/category/([a-zA-Z0-9-/]+)$ /blog/archive.php?cat=$1 [L]
RewriteRule ^blog/category/([a-zA-Z0-9-/]+)/page/([0-9]+)/{0,1}$ /blog/archive.php?cat=$1&page=$2 [L]
RewriteRule ^blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$1 [L]
RewriteRule ^blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$1&page=$2 [L]

RewriteRule ^(css)($|/) - [L]
RewriteRule ^(perch)($|/) - [L]
RewriteRule ^(images)($|/) - [L]
RewriteRule ^(js)($|/) - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

我尝试使用的

RewriteRule ^blog-listing/([a-zA-Z0-9-/]+)$ /blog-listing.php?s=$1&page=$2 [L]

我收到的网址

http://mysite(dot)com/blog-listing.php?page=2

我想要的网址

http://mysite(dot)com/blog-listing/page-2

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

Use a simple file to manage your url

RewriteEngine On

# Redirect all requests not pointing at an actual file to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L] 

https://github.com/ogallardop/blackjack-api/blob/master/src/.htaccess

The framework you're using to pagination will do the rest.