Php 如何将动态URL重写为SEO友好的URL?

Php 如何将动态URL重写为SEO友好的URL?,php,apache,Php,Apache,我尝试了我在这个网站上看到的一切,将动态url重写为SEO友好的url 可能是因为我在本地主机上使用它吗 我尝试了这个,但也不起作用: RewriteCond %{THE_REQUEST} ^GET\ /index\.php/?([^ ]*) RewriteRule ^index\.php/?(.*) /$1 [R,L] RewriteCond $0 !^index\.php($|/) RewriteRule .* index.php/$0 [L] 我还提到了一个在线动态url生成器,但它也不

我尝试了我在这个网站上看到的一切,将动态url重写为SEO友好的url

可能是因为我在本地主机上使用它吗

我尝试了这个,但也不起作用:

RewriteCond %{THE_REQUEST} ^GET\ /index\.php/?([^ ]*)
RewriteRule ^index\.php/?(.*) /$1 [R,L]
RewriteCond $0 !^index\.php($|/)
RewriteRule .* index.php/$0 [L]
我还提到了一个在线动态url生成器,但它也不起作用。请帮忙

我想重写以下两个URL:

index.php?p=home
index.php?p=about me
index.php?p=contact me
您可以使用这个:

RewriteEngine on

RewriteBase /

 # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?q=$1
然后在index.php页面上,所有变量都可以通过$_GET['q']访问。如果您进一步使用$location=array_filter(分解('/',$_GET['q']);然后$location将是一个包含每个目录的数组,因此www.mysite.com/firstdir/seconddir/thirddir将$location[0]作为“firstdir”,而$location[1]作为“seconddir”,依此类推。然后,您可以将它们与数据库中的url_别名进行比较,以确定要显示的内容/模板

这也适用于我的localhost,但我将基本url部分从“/”更改为“/mycurrentconstructionsite/”

希望有帮助

您可以使用这个:

RewriteEngine on

RewriteBase /

 # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?q=$1
然后在index.php页面上,所有变量都可以通过$_GET['q']访问。如果您进一步使用$location=array_filter(分解('/',$_GET['q']);然后$location将是一个包含每个目录的数组,因此www.mysite.com/firstdir/seconddir/thirddir将$location[0]作为“firstdir”,而$location[1]作为“seconddir”,依此类推。然后,您可以将它们与数据库中的url_别名进行比较,以确定要显示的内容/模板

这也适用于我的localhost,但我将基本url部分从“/”更改为“/mycurrentconstructionsite/”


希望有帮助

内部服务器错误服务器遇到内部错误或配置错误,无法完成您的请求。请与服务器管理员联系,admin@localhost并告知他们错误发生的时间,以及您可能采取的任何可能导致错误的措施。有关此错误的详细信息可以在服务器错误日志中找到。是否复制粘贴该错误?如果您在根目录中,请确保保留/if;如果您需要其他目录,请确保保留用户“/mydirectory/”。。。如果您使用的是localhost/mytestsite(例如通过xampp),那么请执行
code
RewriteBase/mytestsite/
code
,其余部分保留原样,先生,实际上,我把.htaccess文件放在我的DynamicWebsite文件夹中,将所有web文件放在一起。内部服务器错误服务器遇到内部错误或配置错误,无法完成您的请求。请与服务器管理员联系,admin@localhost并告知他们错误发生的时间,以及您可能采取的任何可能导致错误的措施。有关此错误的详细信息可以在服务器错误日志中找到。是否复制粘贴该错误?如果您在根目录中,请确保保留/if;如果您需要其他目录,请确保保留用户“/mydirectory/”。。。如果您使用的是localhost/mytestsite(例如通过xampp),那么请执行
code
RewriteBase/mytestsite/
code
,其余部分保留sameyes,先生,实际上我将.htaccess文件放在我的DynamicWebsite文件夹中,将所有web文件放在一起。