I'm having a problem. I'm trying to get this url:
mySite.com/index.php?url=category/value1/value2/value3
From this:
MySite.com/category/value1/value2/value3
I have this .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
</IfModule>
everything is working fine if category is everything but "index", so if I put the URL:
MySite.com/content/tv/color
The array $_GET is equal to:
Array
(
[url] => content/tv/color/
)
but when i put:
MySite.com/index/option1/option2
the array is empty
Array()
I checked my apache.conf file and I can't see the problem.
<VirtualHost *:80>
ServerAdmin user#site.com
DocumentRoot /home/htdocs
<Directory />
AllowOverride all
</Directory>
<Directory /home/htdocs>
#>>>>>HERE I HAVE MY TEST APP <<<<<<<<
DirectoryIndex index.html index.php
Options FollowSymLinks MultiViews
RewriteEngine ON
AllowOverride all
Order allow,deny
allow from all
</Directory>
Alias /simplesaml /var/simplesamlphp/www
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
You need to turn off MultiViews option by prepending minus sign - before it like -MultiViews.
Actually I'm not sure why you turned it on explicitly. Was it just a config copy-paste?
Also if you don't need FollowSymLinks (I'm sure you don't need it) - turn it off as well.
Related
I am having an issue with getting Laravel to work properly with Apache2. This is my config file, but whenever it go to my domain I see directory list, and I need to enter to portfolio/public to see the app. That's also what the url become (my-website.com/portfolio/public/).
Is there any way I can fix this?
I've been trying to deploy this app for 3 days and still had no success...
Great Thanks!
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName my-domain.com
ServerAlias www.my-domain.com
DocumentRoot /var/www/html/portfolio/public
<Directory /var/www/html/portfolio/public>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<Directory /var/www/html/portfolio/public>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory /usr/lib/cgi-bin>
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
This might help you
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public/index.php/$1 [L]
Source
Possible Duplicate
I did the same. But instead of using .htaccess I put these lines
RewriteEngine On
RewriteCond %{HTTP_HOST} ^one\.domain\.com
RewriteRule ^(.*)$ /folder/$1 [R=301]
to /etc/apache2/sites-available/default.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All // I even changed None to All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All // I even changed None to All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine On
RewriteCond %{HTTP_HOST} ^one\.domain\.com
RewriteRule ^(.*)$ /folder/$1 [R=301]
</VirtualHost>
After restarting apache2, When I browse one.domain.com , Mozzila, IE Chrome not responding, But safari gives error
Since it's a 301 you're telling the browser to redirect to one.domain.com/folder which still passes your host condition. Meaning on redirect 2 you're on page one.domain.com/folder/folder
I'm trying to rewrite /test to /test.php. If I go to the link directly it will give me the php page that works but when I go to /test it just gives a 404 not found error. I have enabled mod_rewrite and given the /var/www 755 permissions.
.htaccess
RewriteEngine On
RewriteRule ^test test.php [NC]
test.com.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName test.com
ServerAlias www.test.com
DocumentRoot /var/www/test.com
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/test.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
FIXED: Changed FollowSymLinks to +FollowSymLinks
If you use RewriteLogLevel you will see what the server does. In your case, you will see a applying pattern '^test' to uri '/test'. Update your rule to :
RewriteRule ^/test$ /test.php [NC]
I've been reading up on this on the web, but still could not figure out how to implement it properly. I'd greatly appreciate if you could help me understand how to make url rewrite work without .htaccess.
To check if mod_rewrite is enabled, I ran command ~# sudo apachectl -t -D DUMP_MODULES. It produced, among others the following module: rewrite_module (shared). I don't know if it is the same as mod_rewrite?
Folder /etc/apache2/mods-enabled/ has file rewrite.load
I'm not clear which file exactly I should add rewrite rules to?
File httpd.conf located in /etc/apache2/ is empty. However there's a file named 000-default located in /etc/apache2/sites-enabled/ and it looks like this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
I'm not clear at all where I should add rewrite rules. I tried adding them to this 000-default file into <Directory /var/www/> section, but it did not work.
You put the rewrite code in the directory block where you're have the .htaccess file (if you use them). For example if /var/www is your docroot, you could put it their:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
</Directory>
If you are using apache 2.2.16 or newer, use
FallbackResource /index.php
I have a problem with my apache2, the url rewriting don't work and I don't know why...
In my phpinfo(), I have:
Loaded Modules: mod_rewrite
My .htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^test\.html$ /test.php [L]
My Apache config:
<VirtualHost>
ServerAdmin mail#gmail.com
ServerName www.site.com
ServerAlias site.com
DocumentRoot /var/www/site.com/
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/site.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
I think my config is right, but I really don't know why my rewriting don't work... Have you an idea ?
Thanks you so much !
For this particular rule:
RewriteRule ^test\.html$ /test.php [L]
Mod_negotiation is going to try to deal with it for you. You want to turn Multiviews off if you want that to work:
Options -Multiviews
at the top of your htaccess file, or remove it from your <Directory> container:
<Directory /var/www/site.com/>
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>