2017-04-04 137 views
0

我需要幫助.htaccess文件和URL重寫。我在這裏搜索了所有的問題和答案,我堅持了它。使用.htaccess從URL中刪除空格和html特殊字符

所以我需要一個幫助,用-來替換空格%20來製作一個SEO友好的URL。

當前URL http://localhost/blog/Blog%20of%20the%20day

這裏是我的.htaccess文件

RewriteEngine On 
# Removes .php extension from inner_blog.php 
RewriteRule ^blog/?$ blog.php [NC] 
# Remove inner_blog.php and changing it to blog/articlename 
RewriteRule ^blog/([^/]*)$ /inner_blog.php?title=$1 [L] 
# Need to replace %20 with - from URL 
# Current URL http://localhost/blog/Blog%20of%20the%20day 
# Need to be http://localhost/blog/Blog-of-the-day 
# Was like http://localhost/inner_blog.php?title=Blog%20of%20the%20day 

回答

0
// Start or After "/" 
RewriteRule ^(.*/|)[\s%20]+(.+)$ $1$2 [L] 

// End or Before "/" 
RewriteRule ^(.+?)[\s%20]+(/.*|)$ $1$2 [L] 

我遇到了一個以前的項目這一問題,並得到了這個線程的答案。

相關信息:htaccess clean urls & replacing whitespaces and %20 with -

+0

好吧,我有取代空白 - 但仍然我不是geeting乾淨URL –

+0

anybosy可以解決這個問題 –

相關問題