I am using .htaccess file for redirecting page. I have tried both paths, absolute and relative, but in both the cases I am getting error: URL not found (404).
Please guide me proper way to mention path in .htaccess
RewriteRule ^/abc/([a-zA-Z0-9]+)/?$ /abc.php?tag=$1
You may need to RewriteBase /.
Try adding that just before your RewriteRule, i.e:
RewriteEngine On
RewriteBase /
Also try removing the slash before abc:
RewriteRule ^abc/([a-zA-Z0-9]+)/?$ abc.php?tag=$1
One good way to debug the URL rewriting, is to switch on the rewrite logging.
In Apache 2.2:
RewriteLog file-path.log
RewriteLogLevel 3
The syntax is different for Apache 2.4. Read more here.
Related
I have a web server using apache2, and I want to silently redirect some pages.
So if an user try to access "http://website.com/test.php", the page at "http://website.com/fool.php" will be used instead. And i need to do that for several pages, not just test.php.
I though I could use the mod_rewrite module for this purpose, but I cant get it working.
I tried adding in apache2.conf, so i could have at least just a redirection for now (not silent):
RewriteEngine on
RewriteRule "^/test.php$" "/fool.php"
or
<Directory "/var/www">
RewriteEngine on
RewriteBase "/var/www"
RewriteRule "^/test.php$" "/fool.php"
</Directory>
This result in the test.php not being redirected at all (it still can be accessed), but also, it breaks my custom 404 and 403 pages with the error "ForbiddenYou don't have permission to access this resource.Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.".
Apache2 is not complaining about the syntax when i restart it.
Setting it in my sites-enabled config leads to the same result.
Note that the goal is not to prevent the direct access to test.php, and the request must result in a 200 success code.
There may be something i do not understand, because searching on the net, it looks like it's the way to achieve this.
You may try an alternative method: use the .htaccess file. (place the file in the root directory of your site)
For example:
RewriteEngine on
RewriteRule ^/test.php$ /fool.php [L]
I have all my folders and files in www.mysite.com/magento/ and my home page base url is www.mysite.com/magento/. I need to change this url to only www.mysite.com and if possible I don't wanna move my files from /magento/ to the back folder.
If I use System - Configuration - Web from my magento-admin-panel, it doesn't work and I can't connect to panel.
You should be able to accomplish that using .htaccess and RewriteBase.
Here's commented out example in Magento .htaccess sample:
############################################
## you can put here your magento root folder
## path relative to web root
RewriteBase /magento/
That should do the trick in your case.
You can read more about RewriteBase here: http://httpd.apache.org/docs/current/mod/mod_rewrite.html#page-header
Edit: In the web root, you'll need some sort of rewrite to Magento root directory:
RewriteEngine on
RewriteCond %{REQUEST_URI} !magento/
RewriteRule (.*) /magento/$1 [L]
Keep in mind that there are all just untested examples that should point you in the right direction. :)
Cheers.
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
I´m trying to do a simple redirection with Apache2 with mod_rewrite. I've installed the module in my Apache and I´ve set a webpage in localhost/file1/file2/page.html. I´m writing this in my 000-default file:
RewriteEngine On
RewriteRule elegantdirectory/page.html file1/file2/page.html [L,NC]
So now if I try to access to localhost/elegantdirectory/page.html, the server is supposed to show me the page.html I have in file1/file2. Any ideas why isn't it working?
Try including bounds and a leading slash in your RewriteRule:
RewriteRule ^/elegantdirectory/page.html$ /file1/file2/page.html [L,NC]
I have the following rewrite rule, but nothing is hapenning at all when I try to use it. I have the file in the directory server.blahblahblah.com/todo and the following is my .htaccess file:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^tasks/view/([0-9]+)?/$ controller.php?task=view&id=$1
RewriteRule ^tasks/view/([0-9]+)\.xml$ controller.php?task=viewxml&id=$1
RewriteRule ^tasks/new?/$ controller.php?task=new
RewriteRule ^tasks/delete/([0-9]+)?/$ controller.php?task=delete&id=$1
RewriteRule ^tasks/completed/([0-9]+)?/$ controller.php?task=complete&id=$1
RewriteRule ^tasks?/$ controller.php?task=home
Does anyone know why this won't work at all?
Thanks,
Tim
If nothing happens at all, it might be that you didn't enable .htaccess files for your site. To do that, change your site configuration (/etc/apache2/sites-enabled/<yoursite>) to include AllowOverride All instead of AllowOverride None (the default). But mind the performance disadvantage - you could also put the rules directly in the site configuration.
In case that doesn't solve it, look at the Apache logs in /var/log/apache2/*.