Ok, have a client that has existing links coming in from searchmarketing. I am in process of migrating the program from Cold Fusion to PHP.
RewriteEngine on
RewriteRule ^cat_ap~([^~]+)~(.*)\.htm$ /urban/cat_ap.php?$1=$2 [R]
Currently I have a URL structure:
http://www.test.com/urban/cat_ap~nid~5964.htm
which the above rewrite rule changes to
http://www.test.com/urban/cat_ap.php?nid=5964
Now I want to be able to get the variables out of the query string but maintain the url in the browser to the original http://www.test.com/urban/cat_ap~nid~5964.htm but still have it go to the PHP page.
So that when someone goes to http://www.test.com/urban/cat_ap~nid~5964.htm it actually goes to http://www.test.com/urban/cat_ap.php?nid=5964 but still shows http://www.test.com/urban/cat_ap~nid~5964.htm.
Any ideas on how to do this?
Thanks
Mike
You are already doing this on this line (but change the R flag to L):
RewriteRule ^/urban/cat_ap~([^~]+)~(.*).htm$ /urban/cat_ap.php?$1=$2 [L]
The URL that the user hits will still show as the .htm version while the server processes it as the .php
The R flag explicitly induces an external redirect. So just remove the R flag.
I think you'll need to set up reverse proxying to achieve the desired behaviour, and use the P flag with your rewrite rules. I've used a site with this sort of configuration before, so can say that it works, but I'm afraid I've never configured it myself :-(
A good first step at least would be to install mod_proxy and get it loaded and running. The mod_rewrite cookbook page on the P flag has a small amount of detail on proxying RewriteRules, and links through to the ProxyPassReverse directive documentation at apache.org.
Related
Quick question-
Noticed a problem on my Magento 1.7. Consider the site http://www.seacadetshipsstore.com/magento/. This site has a sub-store that's /magento/gearlocker/. The two should be isolated - if you go to /magento/gearlocker/, you shouldn't interact with the generic store at /magento/ at all.
Here's the problem: the store's base URL is set explicitly to http://www.seacadetshipsstore.com/magento/gearlocker/. When users navigate to http://seacadetshipsstore.com/magento/gearlocker/ (no www), they get redirected to http://www.seacadetshipsstore.com/magento/.
My question is this: if a user navigates to the gearlocker site without www, is there a way to set a second store URL to prevent a redirect? Or would it be easier to control that redirect back to /magento/gearlocker/, instead of /magento/? Any thoughts, solutions, or references would be greatly appreciated. Thanks!
See my comments above. Thanks #CodeMoose
RewriteEngine On
RewriteCond %{HTTP_HOST} ^seacadetshipsstore.com
RewriteRule (.*) http://http://www.seacadetshipsstore.com/magento/$1 [R=301,L]
If I remember correctly I believe duplicate urls across multiple stores are not possible without one of the urls being auto incremented with a -1 -2 etc. Please try modifying one of the url keys and let me know what happens.
I’ve got this problem: Magento redirection problem after moving
I changed local xml, deleted cache, changed secure and unsecure link, everything… It doesnt’ work. The only difference is that I duplicated my installation on the same server and I changed subdirectory’s name for the second installation. But I tried also on another server and is almost the same, except for the fact that it keeps linking me back to Google, and not to old domain.
I noticed that if, on the other server, I don’t change subdirectory’s name everything works (and I don’t understand why) but I want on the same server 2 identical installation with 2 identical databases. How can I? What’s the problem? How can I avoid this wrong redirect?
Magento relies heavily on caching. I've noticed in the past I've had to clear my browser internet cache before the redirects updated.
Also if you cloned/duplicated the code & database, its likely you will have the old URL's in the rewrite module. Have you tried reloading all the indexes after moving and changing the URL's in the magento configuration?
Worst case you may have to change the URL in the core_config_data table in the database.
There is no reindex required for base_url to be taken in account.
Only cleaning cache is required. Are you sure you did it well ?
What cache system are you using ?
What did you changed in your local.xml for this ?
Are you sure you didn't left old information in a local.bak.xml for example ? Magento reads every xml file in /app/etc
I have encountered this when moving, and it ended up being that my .htaccess file still had an old rewrite rule pointing to the old domain. In case someone else has this issue for which the other suggestions to not apply, look for something like this:
RewriteCond %{HTTP_HOST} !^www\.localhost\.com$ [NC]
RewriteRule ^(.*)$ http://www.localhost.com/$1 [R=301,L]
and make sure obviously that the localhost.com matches your domain (the above simply redirects with a 301 permanent redirect rewrite any request that does not begin with www.localhost.com to http://www.localhost.com/ (such as the non-www localhost.com)
I've got a .htaccess file that's attempting to force trailing slashes.
I've previously asked this question on Server Fault because I had assumed that it was purely a server question, but I now have a sneaking suspicion that my problem is related to jQuery Mobile.
Please reference this Server Fault question for the .htaccess configuration.
From that question, the result of visiting http://domain.tld/mobile/hoursis:
http://domain.tld/var/www/html/mobile/hours/
where it should be:
http://domain.tld/mobile/hours/
The entire site is written in jQuery Mobile, and although my expertise is limited, I think this bug/drawback might have something to do with the problem.
This is definitely a mod_rewrite issue, not jquery mobile as the var/www/html is a part of the file path for the server which jquery has nothing to do with.
Have you tried setting a rewrite base? Add the following after turning the rewrite engine on
RewriteBase /var/www/html/
This should have been asked in your original question on ServerFault as the answer has nothing to do with your client library. Instead, you pobably just have to add a L (and probably QSA too) to the list of flags of your RewriteRule like
RewriteRule ^(.+[^/])$ /$1/ [R,L,QSA]
See http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_r for more information.
Actually the thing is that i'm having a sub domain (example.domain.com) which is redirected from other domain of a folder (www.domain/folder) . but need the rewrite rule for my sub domain which shows the url links for the main domain ie., www.domain/folder/path
i need to get as example.domain.com/path. Instead of getting the main domain path i need to expose the URL with sub domain path.
As far as I can tell, there are two ways to do what you are wanting. Both of them require significant extra overhead. Both are also likely to require example.domain.com to lie about who it is.
I wouldn't recommend either if you can avoid it, but.
Method #1
Set up a transparent proxy on www.domain.com/folder to show the contents from example.domain.com. If I recall correctly, this can be done with mod_proxy, but I don't remember how specifically.
Method #2
Set up a rewrite rule on www.domain.com/folder to redirect to example.domain.com. Then set up example.domain.com to either lie about who and where it is, or fix all links in pages on example.domain.com to explicitly go to http://www.domain.com/folder.
In the root .htaccess file on www.domain.com: (to redirect to the subdomain)
RewriteRule ^folder/(.*) http://example.domain.com/$1 [R, L]
Actually the subdomain is created from godaddy account and the maindomain/folder is in other hosting server... masking can be done in top address bar but when i hover through links the actual URL path is displayed in lower left corner of the browser....
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} {HTTP_HOST}[a-zA-Z0-9.-]mydomain/folder/(.)
RewriteRule ^/folder/(.*)$ http://abc.example.in/$1 [L,R=301]
Some one has mailed me the above rewrite rule but still the problem persists...
I have been working on this issue from couple of days and i came to conclusion that
1)From godaddy account i have created a subdomain and forwarded with masking to the actual IP address of the virtual host server, but here comes the problem...
i could not forward to the (domainname/foder) rather i can do it for domainname
So i stuck up here for the solution
If u find a solution i would be considered them as a GENIUS......
I'm trying to install SilverStripe and during the installation, it returns an error saying that friendly links aren't working. However mod_rewrite is enabled and AllowOverride is set to All. I'm using CentOS Linux on a dedicated server with Webmin as the cp (yes, I know.. not my choice).
The installer should have set things up as best it can, even if you receive that error message.
This question is a little tricky to answer because the problem could lie in a number of different places, but I've tried to put together a troubleshooting guide below.
Note: Many of the links below have been deliberately broken because Stack Overflow think I might be a spammer. ;-)
Assuming that your site is at http:/www.example.com, try visiting http:/www.example.com/dev/build - you should see a page with a heading "Environment Builder (formerly db/build)". If that works, then you have no problems with rewrite, and the installer gave you that message in error.
If that gives you a 404, try http:/www.example.com/sapphire/main.php?url=dev/build - this will visit the same feature, but bypasses mod_rewrite. If that gives you the heading "Environment Builder (formerly db/build)" and the previous URL didn't, then you have a problem with mod_rewrite and not some other problem.
Check the content of your .htaccess file. It should look something like this but may have RewriteBase line.
Try putting some junk text - e.g. 'asdfsahjadsfasdf' - into the .htaccess file and saving. Open your site. Does it give you a 500 error? If not, then your AllowOverride All setting isn't working. Check that you have set it in the right place. Remember - it needs to be in your Apache config file, and not the .htaccess. If you don't have access to the relevant config files you might need to ask your ISP to help you answer this question.
If that doesn't uncover the issue, we'll have to tinker with the rewrite rules to see if we can explore what's going on. Try changing this line:
RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
To this (it will turn the rewrite rules into redirection rules):
RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L,R]
Visit http:/www.example.com/dev/build again Did it redirect anywhere? If not, then mod_rewrite isn't working. It should be redirecting to http:/www.example.com/sapphire/main.php?url=dev/build. Is it redirecting somewhere else? For example, has extra junk been inserted into the ?url= parameter? This can sometimes happen if you are running SilverStripe in a subdirectory. In this case, check that the RewriteBase setting is set that subdirectory. Something like RewriteBase /mysubdir.
If you're still unable to get friendly URLs working, then congratulations - you've found a really nasty edge-case! Post the details of what you discovered following the steps above to the SilverStripe IRC channel or Forum on www.silverstripe.org.
Step 1. Put some garbage in your .htaccess file and see if the web server gives you an error.
The point here being to find out - assuming the server is running Apache - whether the .htaccess file the SS installer generated is actually being read. If you've still problems, try asking on the SS IRC channel.