Forum Moderators: phranque
I am working on a site which there about 30 rewriterule in the site .htaccess file.
like :
RewriteRule ^News([0-9]*)_page([0-9]*).html files.php?name=News&id=$1&page=$2
RewriteRule ^Info([0-9]*)_page([0-9]*).html files.php?name=Info&id=$1&page=$2
I've set up wildcard subdomain lately. I'm using it for states and cities. for example :
[state1.example.com...]
I have added such line to check if subdomain is working :
RewriteCond %{REQUEST_URI} !^/index1\.php
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule ^$ /index1.php?user=%1&page=home [L]
and it is working fine.
I want to know if there is someway I could add "state=%1&page=home"
to the end of every address i have. for example :
by this address :
[state1.example.com...]
it gives me :
files.php?name=News&id=100&page=2&state=state1&page=home
as I said, if it saw there's sudomain, then it adds &state=state1 to that address.
Is that possible?
Thanks in advance
p.s what about it adds &state=state1&city=city1 by state1.example.com/city1/ ?
Also a bit confused by the relationship between your "test rule" and the problem as a whole.
If you want to *keep* the query string sent by the browser, then use the [QSA] flag on RewriteRule -- See the mod_rewrite documentation. Otherwise, we're talking about a modification to your rules, but I'm not sure about the specifics.
mod_rewrite is client-request (URL) -driven. We need to know what URL is requested by the browser, and what filepath and query string you want that URL to resolve to. If you are testing and have a problem, we also need to know what filepath and query string you wanted, and what filepath and query string you actually got.
Jim
The site has about 30 rewrite rule. it is making php urls, to html friendly urls.
Now i've added subdomains so I could have 2 differend addresses for each previous url , for example :
http://www.example.com/news123.html
[state1.example.com...]
I want to get from the first this :
http://www.example.com/file.php?name=News&id=123
and this one from the second :
http://www.example.com/file.php?name=News&id=123&state=state1
As you see te difference is that the seoncd one has "state=state1" more.
Now that I have like 30 kind of this rewrite rule, I was wondering if I could add one line, so that it cover all 30 rewrite rules.
a rule like : If there was a subdomain, then add "state=state1".
Sorry If i wasn't clear enough.
If you generate enough duplicate content, you may invoke a filter. If you generate a ton of duplicate content, you may invoke a penalty.
As far as what I see here, you need two rules: One to handle the case with a "state" subdomain, and the other to handle URLs without the state subdomain. Aside from the state/no-state distinction, you only need one rule, not 30. Everything else can be done in a single rule with back-references to copy the appropriate subdomain and URL-path-parts into the two or three query string variables. See mod_rewrite RewriteRule "back-references" documentation at Apache.org.
Jim
For something like this : state1.example.com/city1/
I wrote :
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule ^$ index.php?state=%1
RewriteRule ^.*/$ index.php?state=%1&city=$1 [L]
the state1.example.com is working fine. but state1.example.com/city1/
is not working.
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule ^$ index.php?state=%1 [L]
#
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule ^([^/]+)/$ index.php?state=%1&city=$1 [L]
is there anyway I could check how my code work in .htaccess?
atm I do te changes, upload it on the server and test on the site. If the code is wrong it mess up the site and i have to change it back.
since I have about 500,000 views per month, I don't wanna "test" it till i get the desire result.
p.s How many rewrite rules in htaccess is normal ? I mean won't slow down the site ...
RewriteCond %{REMOTE_ADDR} ^192\.168\.10\.12$
RewriteCond %{REMOTE_ADDR} ^192\.168\.10\. Leave those extra RewriteConds in place until you've thoroughly tested everything, then remove them when finished with testing.
Many Apache developers download Apache or one of the free WAMP, XAMP packages and install it on an old PC for local testing. Apache will run quite nicely on a Windows 95-generation PC; It does not take a lot of CPU power to run Apache -- It's quite small and efficient by modern standards.
Jim