Friendly urls not working - modrewrite enabled. what gives? - mod-rewrite

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.

Related

Wrong redirection to old site after Magento's duplication

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)

Forced trailing slash redirect rule causing strange results

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.

Magento installation Problem in plesk

I have installed magento from Plesk,The home is well,with layout buy when I click any link it show "Not Found" message.
I can not figure out the problem
Thanks in advance.
It looks like you have a problem with Apache mod_rewrite.
Anyway, you can check is it true. Let's just say that you where going to open http://www.example.com/electronics and got 404. Ok, no panic. Try to edit URL to be like this: http://www.example.com/index.php/electronics
If it works, than definitely you have a troubles with one of the following:
Apache mod_rewrite is not enabled. If you can open a page with phpinfo(), you may try to search "mod_rewrite" on that page. No results found -- no mod_rewrite... Call your hosting support.
You need to set RewriteBase directive in your .htaccess file (it may be hidden for web based filemanager). By default the line with RewriteBase is commented, and you can uncomment it and leave it's default value "/" if your Magento is uploaded to document root. If your Magento is in some sub-directory under document root, you need to set RewriteBase value lie this "/my_folder_with_magento".

Managed Fusion Url Rewriter - how to install, get basics working

I'd like to try this out, downloaded it , read the readme, referenced the dll, edited the web.config.
I couldn't find any documentation besides the readme, and it seems that there is a lot to know to get it to work...so, I've been kind of grasping in the dark. I set-up a txt file, didn't know where to put it so dropped it in both the web root and the bin folders. Here is what it now contains:
RewriteEngine On
RewriteRule ^/find/(.*) /index.aspx?k=$1 [NC,L]
I tried building and viewing the site, and tried out the URL with the find/stuff syntax, but I get a 404 error. I would appreciate any advice on how to get this working!
UPDATE: Once I got it basically working, I realized all paths to css and image files, etc., need to be rewritten to absolute paths. I'm still trying to figure out how to have the ASP.Net form post to an absolute path, so that it doesn't post back to the rewritten URL...
This is going to be a multi-decision tree sort of process because of the disconnect between IIS 6 and 7.
Step 1
No matter what version of IIS you use make sure your web.config at least has the following configuration in it:
http://github.com/managedfusion/managedfusion-rewriter/blob/master/Tests/WebApplication/Web.config
Step 2
Next if you are using IIS 6 make sure that wildcards are enabled as outlined in part 3 of the readme. This step is very important, if you skip which 90% of people do who said they read the README nothing will work
Else if you are using IIS 7 make sure the AppPool is setup to use Integrated mode not Classic mode.
Step 3
If everything still doesn't work after that try enabling logging by adding the following right under RewriteEngine On
RewriteLog "log.txt"
RewriteLogLevel 9
This will produce a log file in the root directory of your application. If anything shows up in this log the rewrite engine is working, you just need to tweak your rules.

More Mod_rewrite problems

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.

Resources