2012-03-29 23 views
0

爲了避免Joomla中的URL問題(組件衝突),我必須在斜槓後面加上短劃線:D示例URL「... blog/-article-name」我現在需要的是將「/ - 」重寫爲「/」我花了相當長的一段時間來找到如何使用router.php來做,但沒有成功。現在我請求幫助。有人可以告訴我如何使用htaccess或router.php?
在此先感謝。使用htaccess或router.php重寫Joomla中的URL字符

這是我試圖插入推薦的規則在我的htaccess:

##################################################### 
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE 
# 
# The line just below this section: 'Options +FollowSymLinks' may cause problems 
# with some server configurations. It is required for use of mod_rewrite, but may already 
# be set by your server administrator in a way that dissallows changing it in 
# your .htaccess file. If using it causes your server to error out, comment it out (add # to 
# beginning of line), reload your site in your browser and test your sef url's. If they work, 
# it has been set by your server administrator and you do not need it set here. 
# 
##################################################### 

## Can be commented out if causes errors, see notes above. 
Options +FollowSymLinks 

# 
# mod_rewrite in use 
/********** TRYED HERE ********/ 
RewriteCond %{HTTP_HOST} ^www\.mysite\.com [NC] 
RewriteRule ^(.*)$ http://mysite.com/$1 [L,R=301] 
/********** TRYED HERE ********/ 
RewriteEngine On 
/********** TRYED HERE ********/ 

########## Begin - Rewrite rules to block out some common exploits 
## If you experience problems on your site block out the operations listed below 
## This attempts to block the most common type of exploit `attempts` to Joomla! 
# 
## Deny access to extension xml files (uncomment out to activate) 
#<Files ~ "\.xml$"> 
#Order allow,deny 
#Deny from all 
#Satisfy all 
#</Files> 

## End of deny access to extension xml files 
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR] 
# Block out any script trying to base64_encode crap to send via URL 
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR] 
# Block out any script that includes a <script> tag in URL 
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR] 
# Block out any script trying to set a PHP GLOBALS variable via URL 
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR] 
# Block out any script trying to modify a _REQUEST variable via URL 
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2}) 
# Send all blocked request to homepage with 403 Forbidden error! 
RewriteRule ^(.*)$ index.php [F,L] 
# 
########## End - Rewrite rules to block out some common exploits 

# Uncomment following line if your webserver's URL 
# is not directly related to physical file paths. 
# Update Your Joomla! Directory (just/for root) 

RewriteBase/
/********** TRYED HERE ********/ 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ 
RewriteRule ^index\.php$ http://www.mysite.com/ [R=301,L] 
RewriteRule ^index\.html$ http://mysite.com/ [R=301,L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
/********** TRYED HERE ********/ 

#Check to see if browser can accept gzip files. 
ReWriteCond %{HTTP:accept-encoding} (gzip.*) 
#make sure there’s no trailing .gz on the url 
ReWriteCond %{REQUEST_FILENAME} !^.+gz$ 
#check to see if a .gz version of the file exists. 
RewriteCond %{REQUEST_FILENAME}gz -f 
#All conditions met so add .gz to URL filename (invisibly) 
RewriteRule ^(.+) $1gz [L] 
AddType 「text/css;charset=UTF-8? .cssgz 
AddEncoding gzip .cssgz 
AddType 「text/javascript;charset=UTF-8? .jsgz 
AddEncoding gzip .jsgz 

# Disable calls to user registration or password or username reset ("register", "remind", "reset") 
RewriteCond %{REQUEST_URI} /component/user/(remind|reset|register)(\.html)? [OR] 
RewriteCond %{QUERY_STRING} option=com_user&view=(remind|reset|register) 

# Send all blocked request to homepage with 403 Forbidden error! 
RewriteRule index\.php$ http://new.marioiliev.com/ [R=301,L] 

########## Begin - Joomla! core SEF Section 
# 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !^/index.php 
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC] 
RewriteRule (.*) index.php 
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] 
# 
########## End - Joomla! core SEF Section 

# Deny access to php, xml and ini files 
# within components and plugins directories 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteCond %{REQUEST_URI} \.php|\.ini|\.xml [NC] 
RewriteCond %{REQUEST_URI} \/components\/ [OR] 
RewriteCond %{REQUEST_URI} ^\/includes\/|^\/administrator\/includes\/ [OR] 
RewriteCond %{REQUEST_URI} \/language\/ [OR] 
RewriteCond %{REQUEST_URI} \/libraries\/ [OR] 
RewriteCond %{REQUEST_URI} \/modules\/ [OR] 
RewriteCond %{REQUEST_URI} \/plugins\/ [OR] 
RewriteCond %{REQUEST_URI} \/templates\/ [OR] 
RewriteCond %{REQUEST_URI} \/xmlrpc\/ 
RewriteRule ^(.*)$ index.php [R=404,L] 

# Prevent most common SQL-Injections 
RewriteCond %{query_string} concat.*\([NC,OR] 
RewriteCond %{query_string} union.*select.*\([NC,OR] 
RewriteCond %{query_string} union.*all.*select [NC] 
RewriteRule ^(.*)$ index.php [F,L] 

# Block most common hacking tools 
SetEnvIf user-agent "Indy Library" stayout=1 
SetEnvIf user-agent "libwww-perl" stayout=1 
SetEnvIf user-agent "Wget" stayout=1 
deny from env=stayout 
+0

你的意思' 「/」 到 「/ - 」' ?短跑是否僅在'blog /'後出現? – TryHarder 2012-03-30 04:37:20

+0

其實它的「/ - 」改爲「/」是的這個只會在「blog /」 – memario 2012-03-30 04:59:48

+0

後纔會出現對不起,在你想刪除短劃線之後的斜槓是否正確? **示例**'blog/-articlename'將成爲'blog/articlename' – TryHarder 2012-03-30 05:27:00

回答

0

這應該爲你工作:

RewriteRule ^blog/-(.*) /blog/$1 [L] 
+0

這看起來不錯,但也許我做錯了事,它不起作用。我將編輯我的帖子,並添加我用來顯示在哪些地方我嘗試粘貼此規則的htacces。 – memario 2012-03-30 16:46:22