Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用.htaccess编写更干净的url_Php_.htaccess - Fatal编程技术网

Php 如何使用.htaccess编写更干净的url

Php 如何使用.htaccess编写更干净的url,php,.htaccess,Php,.htaccess,我试图通过更干净的URL获得一个临时的SEO。 下面是我的.htaccess文件: <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ cleanurl2/podtadquery.php [L] </IfModule> 重新启动发动机 重写cond%{

我试图通过更干净的URL获得一个临时的SEO。 下面是我的.htaccess文件:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^ cleanurl2/podtadquery.php [L]
</IfModule>

重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^cleanurl2/podtaQuery.php[L]
以下是我的url当前的外观:

我想要达到的是


请建议我如何做到这一点。感谢您的支持

您可以在/root/.htaccess中使用以下代码

RewriteEngine On
#1)
#Redirect from "/cleanerurl2/podtadquery.php?product=foo&subgroup=bar" to "/cleanerurl2/podtadquery.php/foo/bar"
RewriteCond %{THE_REQUEST} /cleanerurl2/podtadquery\.php\?product=([^&]+)&subgroup=([^&\s]+) [NC]
RewriteRule ^ /cleanerurl2/podtadquery.php/%1/%2? [NC,L,R]
#2)
#Now, internally redirect "/cleanerurl2/podtadquery.php/foo/bar" to "/cleanerurl2/podtadquery.php?product=foo&subgroup=bar
RewriteRule ^cleanerurl2/podtadquery\.php/([^/]+)/([^/]+)/?$ /cleanerurl2/podtadquery.php?product=$1&subgroup=$2 [NC,L]

.htaccess文件中

RewriteEngine On
RewriteRule !\.(?:jpe?g|gif|bmp|png|tiff|css|js)$ index.php [L,NC]
第二行是排除jpg、jpeg、gif、bmp、png、tiff、css和js文件。其他uri将转发到index.php

index.php中

<?php
$uri = rtrim( dirname($_SERVER["SCRIPT_NAME"]), '/' );
$uri = trim( str_replace( $uri, '', $_SERVER['REQUEST_URI'] ), '/' );

echo $uri;
?>
第二步。 打开apacheconf文件

sudo vim /etc/apache2/apache2.conf
取消对此行的注释(大约第187行)

然后在有人的地方找到那条线

<Directory /var/www/>
         Options Indexes FollowSymLinks
         AllowOverride None
         Require all granted
</Directory>

谷歌搜索了一下。花了5秒钟。@DiddleDot这并不是说在我问问题之前我没有用谷歌搜索它,也不是说我的工作做得不够充分。谢谢你的帖子,但我正在努力完成我的代码
AccessFileName .htaccess
<Directory /var/www/>
         Options Indexes FollowSymLinks
         AllowOverride None
         Require all granted
</Directory>
<Directory /var/www/>
         Options Indexes FollowSymLinks
         AllowOverride All
         Require all granted
</Directory>
service apache2 restart