I suppose my domain is "www.domain.com" and I have a file system
public_html
|----ds
|--application
|--cache
|--controller
...
|--css
|--image
|--system
|--index.php
|----zs
|----fd
public_html is root directory.
I coding in .htacess with have condition this ::
1) ds Directory is subdomain. when URL is ds.domain.com. It mapping filepath in www.domain.com/ds/index.php/
2) I want to clean URL form www.domain.com/ds/index.php/translate/paintext (example full url) to ds.domain.com/translate/paintext (clean url)
how to coding in .htacess ?
/ ******************************************************************** /
I put the .htacess in /ds folder and try to coding :
#subdomain to subdirectory
RewriteCond %{HTTP_HOST} ^www.domain.com/ds/
RewriteRule ^(.*)$ http://ds.domain.com/$1 [L,R=301]
#clean URL from codeigniter
RewriteCond $1 !^(index\.php|lib|css|image)
RewriteRule ^(.*)$ index.php/$1 [L]
What is wrong??
At least one thing that is wrong is your HTTP_HOST
. That variable is the hostname , and hostnames contain no URL path info in them. So www.domain.com/ds/
will never exist as a hostname. Change it to:
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^ds/(.*)$ http://ds.domain.com/$1 [L,R=301]
The second issue looks fine. But if you want to redirect a request for /index.php
to a new URL that doesn't have the "index.php" part, you need a new rule to do that:
RewriteCond %{THE_REQUEST} \ /+index\.php/
RewriteRule ^index.php/(.*)$ /$1 [L,R=301]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.