Add prefix to route using apache2 mod_rewrite - mod-rewrite

I'm trying to use apache2's mod_rewrite to add a prefix to all my routes in my symfony2 2.1 project.
Let's say my symfony2 project's root is in /var/www/ProjectFrontEnd.
What I want to achieve is to let the user access the project using http://www.mydomain.com/Project
I have set up this in my virtual host:
DocumentRoot var/www/ProjectFrontEnd
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/Project/(.*)$ /var/www/ProjectFrontEnd/web/app.php/$1 [QSA,L]
When I look at the rewrite log, I can see that the route is rewritten as I expect (rewrite '/Project/' -> '/var/www/ProjectFrontEnd/web/app.php/') but I get a 404 error from symfony and the log says something along the line of request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /Project/" (uncaught exception)
I don't understand why symfony2 still uses the non-rewritten url...
I'd like to specify that prefixing my routes in symfony's routing.yml is not an option.
Is what I want possible to achieve?

In this way it's not possible, cause symfony handles every rewrite as a complete route.
You can simply use the prefix in your app/config/routing.yml. I know it's neccesary for every route import to add it, but the easiest and robust way.
acme_user:
resource: "#AcmeUserBundle/Controller/"
type: annotation
prefix: /Project

Related

Transferring codeigniter HMVC project from localhost to live server

I made a web application on codeigniter HMVC. I tested it on local server and the following link works perfectly fine by giving me a login form, the link : http://localhost/bird_vision/users/login, where my directory structure goes like this bird_vision/application/modules/users/users.php (users->module's name, users.php->controller's name). Now I posted the whole "bird_vision" folder to web using filezilla.
- changed the base_url in config.php file to domain_name
- Made some changes in .htaccess file
# 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?/$10 [L,QSA]
</IfModule>
Now when I write bird_vision.se/bird_vision/users/login in my address bar it gives me 404 page not found. Although when I when type birdvision.se/bird_vision/welcome it gives me welcome to codeigniter page.
Please I need help as my all hardwork making this project is at stake. Thanks in advance.
I figured the problem was not with HMVC but was with codeigniter version 3.0. When it comes to unix(which was the operating system running on my server), it is case sensitive. So when I tried to access the controller it could'nt find the file because of case sensitivity and a 404 popped out everytime.
My folder structure before was something like :
-application
-->modules
--->users
---->controllers
----->users.php
And the link on which I was getting 404 was www.example.com/users/login
where "users" in the link is controller's name within the "controllers" folder under "modules" folder in my case named as users.php and "login" is the function inside the controller.
All I had to do was to change the case of the first letter of my module and controller name. Now my directory looks like
-application
-->modules
--->Users
---->controllers
----->Users.php
note : capitalized "U" in Users module and Users controller.
And the the url I used to access the users controller was : www.example.com/Users/login
And I was back in business.

cjax codeigniter how to install

i have downloaded recently cajax, but I don’t undesrtand how to install.
I have this folder:
Codeigniter/
application/
....
system/
....
I have copied all file in the folder Codeigniter
that:
Codeigniter/
cjax/
...
ajax.php
ajaxfw.php
system/
...
and I written localhost/codeigniter/testing.php?test/test
and result 404 error not found. Please help me with installation I need this framework.
this is my .htaccess if need to change:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Thank you!
Install/Download
http://cjax.sourceforge.net/docs/installing.php
Here are the steps to get the framework installed on your site, or test installation:
1. Download the latest stable release
2. Place the contents of the zip on the root of the site merging it with your current site.
So you'd end up with your current structure plus:
/
cjax/
controllers/
ajax.php
testing.php
You are set. Now lets test...
Testing your Cjax Installation
For security reasons you cannot access ajax.php directly on your browser, so we'll use testing.php to use.
Go onto your browser and type in the url for your site, plus testing.php?test/test, eg: http://yoursite.com/testing.php?test/test
If you see the text "Ajax View..." on your browser, that means you have successfully installed and tested the ajax framework.
You may find the text in file controllers/test.php in function test(). If your installation was successful you may delete file testing.php.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?ajax\/(.*)$ /ajax.php?$1 [NC,QSA,L]
RewriteCond $1 !^(index\.php|assets|robots\.txt|ajax)
RewriteRule ^(.*)$ index.php?/$1 [L]
This worked for me.
For those getting the error "Invalid Function" when clicking "View: test2" - check the URL you land on. In my case (using codeigniter), the code in test.php was missing the initial "/" so that it searches in the current directory instead of the root for ajax.php. Change the last line in /views/test.php
View: <a href='ajax.php?test/test2'>test2</a>
to
View: <a href='/ajax.php?test/test2'>test2</a>
Hope this helps!
Here is the solution to this problem.
You are not taking into account that Cjax is not exclusive to CodeIgniter. There are two different installation instructions, one Cjax universal code base that can be used on any application or website, then there is one version that integrates into CodeIgniter that is the one you are using, though you are following the instructions for the wrong installation.
There are documentations exclusive for Cjax for CodeIgniter, within CodeIgniter's wiki: https://github.com/bcit-ci/CodeIgniter/wiki/ajax-framework-for-codeigniter
Also, some good news: The new version of Cjax, 5.9 is the universal package, but has support built-in for CodeIgniter. This means that from there on, the installation instructions should be on the same place, or should be similar.

Heroku PHP cedar stack: can I do URL rewrites?

I'm running a PHP app on the Heroku cedar stack. Is there a way to set up URL rewrite rules? I had hoped to do this in .htaccess files, but only access control directives are recognized in this.
I see that the Ruby advice is to use rake rewrite, but what needs to happen for a PHP app have URL rewrite configuration on Heroku?
You can use a normal .htaccess file with PHP on Heroku. Simply create a .htaccess file with the re-write conditions, similar to this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
This example lifted from WordPress. I believe all urls now redirect to /index.php. Example here: https://github.com/catsby/php-heroku-htaccess and app here: http://php-heroku-htaccess.herokuapp.com/something
So to partially answer my own question and continue what I alluded to in the comments, here's the difference between a Mac and a heroku .htaccess file that I needed to make:
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ $1/$2?arg=$3 #Mac
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ $1/$2.php?arg=$3 #heroku
This is more of a workaround than a solution. I believe the apache versions are different, but in the end I just capitulated on debugging this further and use a .htaccess file with two sections in it that I comment/uncomment.

issue with shifting Kohana 2.4 from root location to make it accessible via a directory?

I have developed a kohana project 2.4 version, with i has been developed by configuring virtual host and we are accessing it using some domain aa.com, now i have to move the project to folder named kohana and make it access via aa.com/kohana. If i access it this way then my url changes, So the css & js file are not included since the src url i have provided like /public/css/ so it's not working, same goes for calling a controller. like il be calling a controller using this format /user/login/. now the url when i click to shows like aa.com/user/login which is not found, in turn it should automatically comes like aa.com/kohana/user/login. Is there any way by changing the htaccess file or hacking routes.php file. ?
I should able to automatically append /kohana/ before the url.
Please suggest me a method how it can be achieved.
Yes there is!
I've only started after kohana 3.0 but you can just change the rewritebase.
In your .htacces it probably says "rewritebase /"
Change this to your new directory. "rewritebase /kohana/"
If 2.4 has a bootstrap (i'm not sure) somewhere it should say "base_url". You change this the same as the .htaccess. /kohana/.
edit: here's an example:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /kohana/
# Protect application and system files from being viewed
RewriteRule ^(application|modules|system) - [F,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]

Magento URL issues

I am still new to magento but I have been slowly making progress on replicating the production environment to a sandbox environment.
The issue I am currently running into is that when I go to my site I get a long url rather than a short optimized url. I am guessing it is a configuration setting that I need to change as well as, I went through and had to add index.php to the url string for it to work properly.
What I want to be able to do is use a short url such as /category/page.html rather than catalog/category/view/s/power-tools/id/261/
Thank you in advance!
This is probably because you need to reindex Catalog URL Rewrites. Go to System->Index Management and reindex. (It's probably best to select all and reindex though just to be sure!)
After working through this, I ended up changing the .htaccess Mage::run() settings. I ended up having to change some of the base url setting in the core_data_config table to finish getting everything to work correctly. I also ended up having to set the SEO rewrites (System Config > General > Web > Search Engine Optimization > Use Web Server Rewrites) = No
I found that once index.php was included in the path then my site was working properly.
This is what i ended up doing and it removed the index file as well. Part of the issue is that I installed magento in /store/dir/
1) Login to admin section by using the URL
http://domain.com/index.php/admin
2) then go to “System >> Configuration >>Web >> Search Engines Optimization”
Use Web Server Rewrites : YES
3) Go to “System >> Configuration >>Web >>Secure”
Use secure URL Frontend: YES
** I used the second one **
4)Then create the .htaccess file under your the magento installed folder.
If the magento installed under document root ( /home/username/public_html) then add follogig rules into .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
and If the magento installed under /shop or directory then add the following rules into ” /home/username/public_html/shop/.htaccess ” file.
<IfModule mod_rewrite.c >
RewriteEngine On
RewriteBase /shop/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /shop/index.php [L]
</IfModule >
http://www.bestdesigns.co.in/blog/remove-index-php-url-magento

Resources