Yii :: Issue Using Showscriptname = False And Url Manager - url-rewriting

I am currently having an issue using the URL manager and/or the apache mod_rewrite or maybe something else entirely.
With showScriptName set to false, navigating to addresses such as domain.com/login, domain.com/logout, domain.com/site/login are all behaving the same way. It simply shows the main site/index, as if I were to navigate to domain.com/eeofjew9j8jfdedfmewf (jibberish).
Maybe it's an issue with my Yii settings? Here are those (sorry for the sloppiness):
'components'=>array(
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'login'=>'site/login',
'logout'=>'site/logout',
'register'=>'users/register'
),
,...
Here is how I have my .htaccess setup in the www root:
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
I am using a VPS server, so I have root access to make any changes needed to apache. I've checked my phpinfo and mod_rewrite is running and enabled. In my apache config, I have for my www directory:
AllowOverride All
Options Indexes FollowSymLinks MultiViews
Order allow,deny
Allow from all
I've been scratching my head on this issue through 3 different hosts (godaddy, dreamhost, and lithiumhosting) so I'm assuming it's an issue on my end with this. Now that I have a VPS though, I'm hoping I can finally figure out my issue and solve it.

First verify that the server is parsing the .htaccess file. This is simply done by placing random text in the .htaccess file such as
CREATE AN ERROR
If this gives you a server error then the file is being parsed. You may have to move the .htaccess file up a directory to get this to work.
After this is working check to make sure the rewrite module in Apache is on. First check phpinfo and look for the running module. If not you may have to delete the comment (#) character in front of the module.
After the module shows up in phpinfo then see if you can do a basic rewrite to make sure that there are not problems with Apache.
RewriteEngine on
RewriteRule ^ http://google.com/? [L,R]
If that is not working try adding the
Options +SymLinksIfOwnerMatch
to the file
Once you have Apache doing it's part now it is up to yii. This code:
RewriteEngine On
RewriteBase /mybasedirectory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]
adds the rewrite base option which may be necessary if you do not have the files in the document root such as htdocs
finally if that does not solve the problem then limit your rule to a simple rule such as
'contact'=>'site/contact',
and see if at least redirects to where you think it should. Of course you may have to check the basic rules of .htaccess again to make sure that overide is allowed and there isn't an errant .htaccess in a subdirectory. I hope that helps. I finally got mine working.

What happens if you delete these lines!
enter code here
# otherwise forward it to index.php
RewriteRule . index.php

if you add this code see if it works
'<action:(login|logout|register|contact)>' => 'site/<action>',

Related

how to define rewriterules in cloud9 web-ide

I'm playing arround with cloud9 and I would like to define rewrite rules for my apache based web application in c9 web-ide.
I created a .htaccess file (not sure if is located correctly). I guess I need to configure httpd.conf file but can't find such.
how should it be done?
Thanks.
I had this issue. Turned out it was all down to typos in the .htaccess file. No further configuration was required.
I saved the .htaccess file in a folder I created called 'site' which I am using as the root for my web app (so the same folder which contains index.php), i.e. like this: myWorkspaceName/site/.htaccess
The full contents of my .htaccess file is:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
You might copy and paste that to use as a test of the configuration (remembering to save and restart Apache of course).
In case you do need to configure something like httpd.conf it appears that you would want to take a look at the following files as a starting point:
/etc/apache2/apache2.conf
and
/etc/apache2/sites-available/001-cloud9.conf
Access to these files is via the command line, so you would type:
sudo nano /etc/apache2/sites-available/001-cloud9.conf
for example.
It may be worth mentioning that for my specific rewrites, the address I would use has to include my sub folder 'site', i.e,
https://myWorkspaceName-wkille.c9.io/site/anything
whereas
https://myWorkspaceName-wkille.c9.io/anything
throws a Not Found error.

Apache rewrite rule which allows only one query string

I have website at the root of the server
In a subfolder called se i have an installation of drupal, so going to
https://websiteUrl/se
launches drupal. I want only one page of drupal to be accessible and that all other tries go (not changing url so internally please) to this drupal accepted page. This aboslute page url is:
/se/?q=node/555 (se/index.php/?q=node/555 should aussi be rewriten as /se/?q=node/555 )
Other urls that should be rewriten are like se/index.php/?q=string )
i'am fighting with my apache conf file and Directory directive to do that.
here is my httpd.conf
<Directory /var/www/se/>
AllowOverride None
RewriteEngine on
RewriteCond %{QUERY_STRING} q=node/[^555] [OR]
RewriteCond %{QUERY_STRING} ^q=([a-z]*)$
RewriteRule ^(.*)$ /se/index.php?q=node/555 [L,R]
</Directory>
which is Ok for url like index.php?q=node/347 but not ok for index.php?q=searchString. All what i tried to do with a condition where i try to exclude the q=node/555 resulted in a infinite loop or inner javascript / css links being rewritten too (--> bad link)
Thanks !

apache not working with index on RewriteEngine on Mac Lion

I have a strange problem that only happen on My mac(I do not try in another mac, but did tried on a linux and it works)
this is my .htaccess
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?key=$1
on my index.php I put:
echo $_GET['url'];
it is return a empty array if my url is like this:
localhost/test/index/xpto
but it is return 'index2/xpto' if I put this in the url:
localhost/test/index2/xpto
So the problem is with the string index.
Do you guys know why it do not work on my mac but it does on linux?
I am using standard apache on mac os x lion.
I just change this lines on httpd.conf
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
....
<Directory "/Library/WebServer/Documents">
AllowOverride All
...
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
Edited
By working I mean the $_GET['key'] is not empty. And shows the url I put in the browser.
but when I use this url on browser:
http://127.0.0.1/test/index/xpto
my $_GET['key'] is empty
and if I use this url:
http://127.0.0.1/test/anythingbutindex/xpto
the $_GET['key'] have the text:
anythingbutindex/xpto
I did install XAMPP on my mac and this code works fine with index.
So the problem is with the default apache on my MAC.
thanks.
I don't understand how this is working on Linux, or what result that is "working". To me it looks like it's doing what one could expect. I however think your RewriteRule might be a bit wrong. What it will do is that it will pass the entire URI to the index.php file, while I think you just want to parameters after index.php?
If you enter localhost/test/index/xpto, and assuming your DocumentRoot is set to /test the string sent to index.php will be index.php/exto. Same thing apply to index2/exto since the RewriteRule does not care about if you enter index och index2.
You could try this:
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^index/(.*)$ index.php?key=$1
If you do want the index parameter in there you could change the RewriteRule to:
RewriteRule ^(index/)(.*)$ index.php?key=$1$2
Hope it helps you forward.
EDIT
After the clarification I understand the question. Some testing later I found that the solution was pretty obvious, but I did not spot it at first. The RewriteRule is slightly off and if I use this it's almost working on my system.
RewriteRule ^(.*)$ /index.php?key=$1 [L]
Note the / before index.php. However this would always redirect to index.php meaning always match the RewriteCond statements. Changing the statement to this however worked at my system.
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
If you have DirectoryIndex set the !-d is kind of redundant since it will always try <path>/index.html or whatever you have configured.
I've had this issue right now and the easiest way to make it work was reinstalling apache via homebrew, so it works identical to the Linux I'm using on a VPS.
It took about two minutes to reinstall, reconfigure the port and I've used virutalhost.sh script to point to the ~/Sites folder

mod_rewrite newbie - is this correct?

This is supposed to take any uri and send it as part of a query string to a script that will handle it.
RewriteEngine On
RewriteCond %{REQUEST_URI} !(css.php|gif|jpe?g|png|css|js|json|xml|ico)$
RewriteRule ^(.*)(/)?$ index.php?where=$1 [QSA,L]
I'm asking because it works on some servers and not on others. On some it just disregards the whole thing as if url rewriting is off, and on others it reports a bad request whenever .htaccess with the above content is uploaded.
BTH I would change this rule a bit:
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(css.php|gif|jpe?g|png|css|js|json|xml|ico)$
RewriteRule ^(.*)/?$ index.php?where=$1 [QSA,L]
Added \. into RewriteCond pattern to ensure that it only works for files with such EXTENSIONS (otherwise pattern will also match files that have that text at the end i.e. /something/mygif <> /something/my.gif).
Replaced (/) by / in RewriteRule pattern -- it makes no difference in functionality but a bit lighter on resources.
Back to main topic:
If it "disregards the whole thing as if url rewriting is off" then most likely .htaccess files are not supported/enabled (or it should have different name as configured by AccessFileName directive: e.g. AccessFileName ht.access).
To check it try placing some other directives into .htaccess and see if it works (like: ErrorDocument 404 /404.php or DirectoryIndex index.php etc).
If it "reports a bad request whenever .htaccess with the above content is uploaded" then most likely these directives are not allowed to be placed in .htaccess (requires AllowOverride All or at least AllowOverride FileInfo; see docs) or mod_rewrite is not enabled.
Check Apache's error log -- it should have entries mentioning this moment.

Codeigniter: Problem after migration!

I just transferred my local web app to my server, and now I'm getting this error:
Parse error: syntax error, unexpected
T_OBJECT_OPERATOR in
/nfs/c05/h01/mnt/71658/domains/ergo-metric.com/html/application/libraries/Survey_form_processing.php
on line 172
This is odd because it works locally! I changed my db settings to the production server, and my base_url is correct.
Any ideas what this could be?! I'm a little worried b/c this is a live site!
I would start with your php config file, check what is enabled on your end and what is enabled on the other end. but first check your config file and look for rewrite short open tags switch it to true. these are very basic but you didn't give a whole lot of information, maybe post a few lines of code before and after 172 let me see what is going on there. also if you are using htaccess files and are still using the default CI example i would switch it to this works like a charm: this is a universal htaccess file no matter your setup you dont have to change it promise you that the best thing since sliced bread.
# Customized error messages.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
i am going to be on for a while if you reply maybe we can get this worked out for you two heads are better than one thing you know

Resources