I just got fresh debian VPS into my hands.
I installed url rewrite and simple things like this does seem to work
RewriteRule ^login$ /login.php
However this doesn't work:
RewriteRule ^cats$ /index.php?cat=cats
Anyone have idea why?
(it works on local xampp server + it worked on shared host I had)
Thanks
First of all make sure that you have mod_rewrite, and it's on. To do so, create an empty Php file, then add <? phpinfo() ?> and diplay it in your browser.
If it's "on" then you can go on.
If it's in a .htaccess file then try with / without the slashes.
RewriteRule ^cats$ /index.php?cat=cats
Or
RewriteRule ^/cats$ /index.php?cat=cats
And if that's not enough:
Two hints:
If you're not in a hosted environment (= if it's your own server and you can modify the virtual hosts, not only the .htaccess files), try to use the RewriteLog directive: it helps you to track down such problems:
# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On
My favorite tool to check for regexp:
http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)
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 am starting to learn how to work with laravel but got a problem. When I go to: http://localhost/testing/public/ I get a working page but when I typ for example http://localhost/testing/public/home which is one of my views I get a 404 error. Does someone know how to fix this?
Edit:
I am using the latest version of laravel and when I do for example:
Route::view('/home', 'home');
In my routes/web.php I get that error
This is more likely a problem with virtual Hosts, try the following:
First edit your route to :Route::get('/home', function(){echo
"hello"});
Then try to access: http://localhost/testing/public/index.php/home
If it works then its certainly because you don't have a virtualHost, you can set it easily in your Xampp config and modifying ur hosts file
First go to C:\Windows\System32\drivers\etc\hosts and add a new
line like: 127.0.0.1 yoursite.local
Then go to where xampp is installed under
xampp\apache\conf\extra\httpd-vhosts.conf
Then add a virtual host in the bottom of the file like:
<VirtualHost *:80>
DocumentRoot "PATH_to_laravel_folder/public"
ServerName yoursite.local
</VirtualHost>
Then you can access your route by typing: yoursite.local/home or
yoursite.local:80/home
Hope it helps you guys :)
It may be because of routes.
after creating a view you have to add it in routes/web.php
like Route::view('/yourUrl', 'viewName'); in 5.5 version.
for 5.4 or older versions Route::get('/yourUrl', 'viewName');
after adding this to routes/web.php. you can access http://localhost/testing/public/yourUrl
you can find more here
If http://localhost/testing/public/index.php/home works, try to create a .htaccess file in public directory with:
RewriteEngine On
RewriteBase /testing/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Run $ composer install in you command line
I have 1 dedicated server.
The server has several IPs.
Some IP are dedicated for one particular domain.
Ip1 = mysite.be
Ip2 = mysite.fr
Ip3 = mysite.com
There is only one project. Each domain goes on the same location
My website is on /var/www/vhosts/mysite.com/httpdocs
For all other domain, i create a symlink.
/var/www/vhosts/mysite.be/httpdocs -> /var/www/vhosts/mysite.com/httpdocs
/var/www/vhosts/mysite.fr/httpdocs -> /var/www/vhosts/mysite.com/httpdocs
...
When I go on mysite.com, all works.
But when i go on mysite.be ... I have an output from codeIgniter :
No input file specified.
I search more information about this error and I see that : https://stackoverflow.com/a/14578219/905867
My .htaccess fil is already well configured... I guess
Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|css|js|uploads|modules|public|timthumb\.php|\.htpasswd|google.*\.html|captcha)
RewriteRule ^(.*)$ /index.php?/$1 [L]
The fact that the domain linked with symlink display the error "No input file specified." proves that the symlink is OK and the acl on server are OK too (chown and chmod).
I think it's a little thing, but i don't know what. Anyone has a idea please ?
Some others information :
- I manage my server with plesk 11.0.9 #53
- My domain are "php as FastCGI module". If I use "as Apache Module, there is a blank page instead of error "No input file specified."
It takes me long time but... problem is solved.
No input file specified wasn't a CodeIgniter error but a CGI/FastCGI error...
So I check on my plesk an I saw the domain are "PHP as FastCGI module" instead of "PHP as Apache Module".
But... instead of an error, I have a blank page.
Then I thought about open_basedir restriction. It was configured on "Webspaceroot" instead of "Docroot"... and "abracadabra" it works.
Take care !
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]
I'm writing a script to build a dynamic website,
the website is created by loading external components.
The DocumentRoot is location at /sites/website/public
the components directory is located at /sites/website/components
i wannna reach the data directory of each component depends on the requested url.
for example:
the url:
http://ibuildmywebsite/component-data/randomimage/demo/swan04090044_small.jpg
should fetch the file /sites/website/components/randomimage/data/demo/swan04090044_small.jpg
how can i achieve that ?
i would prefer a way that can be placed inside .htaccess (if there is one) instead of modifying the virtual host definitions.
Thanks!
Combine RewriteRule with Alias maybe ?
Alias /randomimage /sites/website/components/randomimage
RewriteRule ^component-(.*)/randomimage/(.*)$ /randomimage/$1/$2 [R,L]
(Won't work in .htaccess though)
You could probably also use Symlinks with:
Options +FollowSymLinks
And link dynamically components-*/randommimage/* to /sites/website/components/randomimage/*/*/