I've just installed Oxwall (oxwall.org) on my shared 1and1 host and would like to remove "index.php" from all URLs.
Essentially PHP needs to see this
http://site.com/index.php/Page/Param1/Param2
While I want the user to see this
http://site.com/Page/Param1/Param2
I understand this should be done using the .htaccess file, but I don't know how to do it...
Currently, .htaccess file looks like this:
Options +FollowSymLinks
RewriteEngine On
AddEncoding gzip .gz
AddEncoding gzip .gzip
<FilesMatch "\.(js.gz|js.gzip)$">
ForceType text/javascript
</FilesMatch>
<FilesMatch "\.(css.gz|css.gzip)$">
ForceType text/css
</FilesMatch>
RewriteCond %{HTTP_HOST} !oxwall.(host).com$
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} !/ow_updates/index\.php
RewriteCond %{REQUEST_URI} !/ow_updates/
RewriteCond %{REQUEST_URI} !/ow_cron/run\.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.xml|\.feed|robots\.txt|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
Any suggestions?
I've found similar messages on stackoverflow, but I wasn't able to apply the proposed fixes to my .htaccess file...
Thank you very much for your time and support!
Found the solution!
Simply used the htaccess code mentionned in this topic: http://www.oxwall.org/forum/topic/7924
Hope this helps others!
Related
I have the urls
https://example.net/app/ref/user/u123456
https://example.net/app/ref/user/u123456/
Need redirect both url to https://example.net/app/ref/user/index.php?referral=u123456
How to do it with a file .htaccess? Unfortunately, I couldn't do it, so I'm asking for your help.
UPD: Now me .htaccess is in the same directory as index.php:
<IfModule mod_rewrite.c>
RewriteEngine on
</IfModule>
AddType application/x-httpd-php .html
<Files 403.shtml>
order allow,deny
allow from all
</Files>
With your shown samples please try following htaccess rules file. Please make sure you keep your .htaccess rules file in your root folder; alongside with your app folder.
Make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*/[^/]*/[^/]*)/([^/]*)/?$ $1/index.php?referral=$2 [QSA,L]
I'm trying to get aphdigital.org/GVH/ to redirect to gvh.aphdigital.org, and aphdigital.org/GVH/something/ to gvh.aphdigital.org/something/ but I'm having quite a lot of difficulty. I tried the code from this question, but it's not working. The commented-out code blocks below also show failed attempts at a redirect. What am I doing wrong? I would enable logging if I had access to httpd.conf, but I only have FTP access. I know apache is reading this file, because syntax errors seem to cause 500 errors.
Here's my .htaccess file:
# Remember to enable display_errors on development environments only.
<IfModule mod_php5.c>
php_value display_errors 1
php_flag register_globals off
</IfModule>
RewriteEngine on
# If know that mod_rewrite is enabled, but you are still getting mod_rewrite errors,
# uncomment the line below and replace "/" with your base directory.
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^admin/ - [C]
RewriteRule .* admin/index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php
# Added this on Jan. 4, 2013 to redirect from old URL to new. Doesn't seem to be working.
RewriteCond %{HTTP_HOST} ^www.aphdigital.org/GVH$
RewriteCond %{HTTP_HOST} ^www\.aphdigital\.org/GVH$
RewriteRule ^gvh/(.*)$ http://gvh.aphdigital.org/$1 [L,QSA,R=301]
# End of Jan. 4 add.
#TEST for redirect added April 3. Also doesn't work.
# To redirect /mysub/foo to http://mysub.mysite.co.uk/foo
#RewriteCond %{HTTP_HOST} ^(www\.)?(aphdigital\.org)$ [NC]
#RewriteRule ^(gvh)/?(.*)$ http://$1.%2/$2 [R=301,L,NC]
#TEST2, code from Stackoverflow question
#Options +FollowSymLinks -MultiViews
#RewriteEngine on
#RewriteBase /
# To redirect http:://www.mysite.co.uk/ to http:://mysite.co.uk/
#RewriteCond %{HTTP_HOST} ^www\.(aphdigital\.org)$ [NC]
#RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
# To redirect /mysub/foo to http://mysub.mysite.co.uk/foo
#RewriteCond %{HTTP_HOST} ^(www\.)?(aphdigital\.org)$ [NC]
#RewriteRule ^(gvh)/?(.*)$ http://$1.%2/$2 [R=301,L,NC]
#END TEST 2
#Intentionally breaking to see if reading .htaccess. Yep, this breaks it.
#<directory / ></directory>
<FilesMatch "\.(php|ini)$">
Order Allow,Deny
Deny from all
</FilesMatch>
<Files index.php>
Allow from all
</Files>
# Uncomment the lines below in order to enable caching of some files via Apache (after a finished site has gone live)
<IfModule mod_expires.c>
# <FilesMatch "\.(js|ico|gif|jpg|png|css)$">
# ExpiresActive on
# ExpiresDefault "access plus 10 day"
# </FilesMatch>
</IfModule>
This is for a site running the Omeka CMS.
The URL path GVH is not part of %{HTTP_HOST}, so this should be
RewriteCond %{HTTP_HOST} ^(?:www\.)?aphdigital\.org$
RewriteRule ^gvh/(.*)$ http://gvh.aphdigital.org/$1 [R,L,NC]
Never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.
I have an htaccess problem with it blocking my directory because of the filesmatch flag.
I'm trying to block log files, but on my site also maintain a blog.
What happens is that if people come to site.com/blog they get a 403 error vs site.com/blog/ works just fine. Also some other functions within the blog fail as well because of this error.
I guess i'm not sure if the filesmatch is correct/working properly or how to fix this. htaccess files have never been my friend :p
Options +SymLinksIfOwnerMatch
# Prevent Directoy listing
Options -Indexes
# Prevent Direct Access to files
<FilesMatch ".(tpl|log|ini)">
Order allow,deny
Deny from all
</FilesMatch>
# SEO URL Settings
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^site.com [NC]
RewriteRule ^(.*)$ http://www.site.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
You need to escape your . in the <FilesMatch> container. It expects a regular expression and the . character means "any character that isn't a newline".
<FilesMatch "\.(tpl|log|ini)">
Order allow,deny
Deny from all
</FilesMatch>
I've got the following in .htaccess:
RewriteCond %{REQUEST_URI} !app/index\.php$
RewriteRule ^(.*\.htm)$ index.php?url=$0 [QSA,L]
Everyting works great but result URLs have empty $_POST.
I'm 100% sure that it's mod_rewrite bug, not HTML or PHP because when I change [QSA,L] to [L] it works great. But I really need QSA.
It happens at about 30% hostings so this may be some Apache config option.
What about modifying your rule in this way. Does it change anything?
RewriteRule ^(.*)\.htm$ index.php?url=$0.htm [QSA,L]
by default,.. maybe apache not enable mod_rewrite, try type this on your console
sudo a2enmod rewrite
sample my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
I had exactly this issue. It works on one server then not the next. Annoying and time consuming to say the least!
After a lot of checking using this php:
foreach ($_REQUEST AS $key => $value) echo $value."<br>";
at the top of the index.php to check what values were being sent from the htaccess file, (and many other checks I will not go into!) I eventually found you need to specify "RewriteBase"
Adding RewriteBase / to the top of the htaccess file made it work on the all the servers I tried.
(also, remember to set to: RewriteBase /folder-where-file-is/
where "folder-where-file-is" is the location of the index.php file if in a sub-folder)
Hope it helps you - knowing this would certainly have helped me many many hours ago!
I have a .htaccess file in the folder "services" in my website
and have to give two urls following
content of htaccess
#------------------------
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ index.php?n=$1 [L,QSA]
</IfModule>
$-------------------------
1. http://www.mysite.com/services/seo-work
2. http://www.mysite.com/services/online-editor
The 1st URL rewritten using htaccess like http://www.mysite.com/services/index.php?s=seo-work
This is working correct. but when i am uploading other file online-editor.php on the same folder "services", it is not working
so how the first url should show the page using index.php?s=seo-work if the page "online-editor.php" is not found in directory otherwise online-editor.php shoud show. I am programatically representing my problem below
if(IsFoundPageInDirectory(online-editor.php))
{
GoToUrl(http://www.mysite.com/services/online-editor.php)
}
else
{
GoToUrl(http://www.mysite.com/services/index.php?s=seo-work)
}
Please help me to get out of this problem
Advance thanks for your reply
There is not really if/else conditions with ifModule in Apache configuration, but you can use the test in 2 cases : !module & module, like this:
<IfModule !module>
# default directives
</IfModule>
<IfModule module>
# decorator directives
</IfModule>
Check default wordpress .htaccess file. I think you're missing checks for existing files and directories. Something like
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
Last I found answer.. thanks for the fist reply to lead me to get answer
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?n=$1 [L,QSA]
</IfModule>