简体   繁体   中英

rewrite based on dynamic url htaccess

I have sites set up as production or dev. in production mode, visiting example.com will allow all dynamic page rewrites to work, in dev, visiting the ip xxx.xxx.xxx.xx/~sitename will also allow rewrites of dynamic pages using the htaccess code below:

# RewriteBase equivalent - Production
RewriteCond %{HTTP_HOST} !^localhost$
RewriteRule . - [E=REWRITEBASE:/]

# RewriteBase equivalent - Development
RewriteCond %{HTTP_HOST} ^xx\.xx\.xx\.xx$
RewriteRule . - [E=REWRITEBASE:/~countryr/]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/-]+)/?$ %{ENV:REWRITEBASE}page.php?pid=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ %{ENV:REWRITEBASE}blog-detail.php?url=$1 [QSA,L]

but I dont always know what will come after /~ for the username, in this code example, the username is countryr, so I can tell htaccess to rewrite to /~countryr and it works, but is there a way to pass this dynamically? so if its /~mysite or /~site2 it will still work? I dont want to have to write the username in all the sites htaccess files.. it a lot of websites.

You can capture username dynamically using:

RewriteCond %{HTTP_HOST} ^64\.6\.104\.14$
RewriteCond %{REQUEST_URI} ^(/~[^/]+)
RewriteRule . - [E=REWRITEBASE:%1/]

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.

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