简体   繁体   English

htaccess重写规则将目录/名称重写为index.php?id

[英]htaccess rewrite rule to rewrite directory/name to index.php?id

I am using this code in my htaccess file: 我在htaccess文件中使用以下代码:

# Rewrites /blog/post-name-1 to be /index.php?post_name=post-name-1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)/?$ /index.php?id=blog&post_name=$1 [L,QSA]

i want to rewrite /blog/post-name-1 to look at /index.php?id=blog&post_name=post-name-1 我想重写/blog/post-name-1来查看/index.php?id=blog&post_name=post-name-1

but it is showing 404 Page Not Found 但它显示404页面未找到

Think you need following: 认为您需要遵循以下条件:

RewriteEngine On
# Rewrites /blog/post-name-2 to be /index.php?post_name=post-name-2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)$ /index.php?id=$1&post_name=$2 [QSA,L]

Try: 尝试:

RewriteEngine On
# Rewrites /blog/post-name-1 to be /index.php?post_name=post-name-1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /index.php?id=blog&post_name=$1 [QSA,L]

Also ensure the following; 还请确保以下内容;

  • You've allowed .htaccess to be the override file on httpd.conf 您已允许.htaccess成为httpd.conf上的替代文件
  • You've set AllowOverride to ALL in httpd.conf 您已在httpd.conf中将AllowOverride设置为ALL

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

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