简体   繁体   English

.htaccess SEO友好网址

[英].htaccess SEO friendly url

I am trying to create a SEO friendly URL for my home page. 我正在尝试为我的主页创建一个SEO友好URL。 For example, I want example.com?url=hello-world to become example.com/hello-world. 例如,我希望example.com?url=hello-world成为example.com/hello-world。 My current .htaccess has the following: 我当前的.htaccess文件如下:

RewriteEngine On

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

It removes .php file extensions correctly, but how can I make it so that it can also generate a SEO friendly url for the home page? 它会正确删除.php文件扩展名,但是如何制作它也可以为主页生成SEO友好的url? The file is index.php. 该文件是index.php。

Try this, 尝试这个,

RewriteEngine On

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

#for pretty url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ index.php?url=$1 [NC,L]

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

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