Merged with htaccess 404 redirect problem.
Here is my htaccess contents below. The 404 redirect is to redirect anyone to the index.htm page if they type in the wrong address or click a link that is broken or moved. The Problem is I get this "No input file specified." when a link is broken or typed wrong, here is an example www.cases.com/1234.htm
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} \.(gif|jpg|jpeg|png)$
RewriteRule .* products/noimage.jpg [L]
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^cases.com [NC]
RewriteRule ^(.*)$ http://www.cases.com/$1 [L,R=301]
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
# Rewrite Rule for blog.cases.com
RewriteCond %{HTTP_HOST} blog.cases.com$
RewriteCond %{REQUEST_URI} !blog/
RewriteRule ^(.*)$ blog/$1
ErrorDocument 404 /index.htm
AddType application/x-httpd-php .htm .html .php
Related
I am trying to achieve a simple http to https redirect and www to non-www. The problem is that .htaccess puts "index.php" before the url slug, resulting in a server error. Here is what happens:
WRONG BEHAVIOUR:
http://example.com/url-slug -> https://example.com/index.php/url-slug
DESIRED BEHAVIOUR:
http://example.com/url-slug -> https://example.com/url-slug
Note: I want all queries to redirect to the index.php page in the main directory, unless the requested file exists on the server. I'd like to achieve this without changing the url in the browser, which causes the server to crash.
(Objective: www -> non-www & http -> https)
CURRENT .HTACCESS SETTINGS:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
What am I doing wrong?
Your http to https 301 redirect should be at the top before other internal rewrite rules
RewriteEngine On
#http to https
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule (.*) https://%1%{REQUEST_URI} [NE,L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Make sure to clear your browser cache before testing this change.
I'm trying to redirect or rewrite a specific page. In my .htaccess I've tried both of these lines but neither worked. The press-releases-news/?lang=en page exists on my site but not /press-releases-news/?lang=fi, so I'm trying to avoid the 404 that results. Appreciate some pointers here.
Redirect 301 /press-releases-news/?lang=fi/ /press-releases-news/?lang=en
RewriteRule /press-releases-news/?lang=fi/ /press-releases-news
Placed directly after RewriteEngine On
<IfModule mod_rewrite.c>
RewriteEngine On
Redirect 301 /press-releases-news/?lang=fi/ /press-releases-news/?lang=en
RewriteRule /press-releases-news/?lang=fi/ /press-releases-news
RewriteBase /
RewriteRule ^(.+)\.aspx?$ handleRedirect.php [L,NC]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Try:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{QUERY_STRING} lang=fi
RewriteRule ^press-releases-news http://yourdomain.com/press-releases-news [R=301]
I have created a www.example.com and m.example.com. The m.example.com resides inside the htdocs/m/ folder. I am also deleting the '.php' extensions using .htaccess. I am having the below codes on the root directory:
RewriteCond %{REQUEST_METHOD} =POST
RewriteRule ^ - [L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1%2 [R=302,L,NE]
#mobile
RewriteCond %{HTTP_HOST} ^m\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/m(/|$) [NC]
RewriteRule ^(.*)$ m/$1 [L]
# Resolve .php file for extension-less php urls
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
I have forms in the m.example.com. For example in m.example.com/myform.php, I have
<form method="post" action="processform.php">
.....
</form>
I want it to be submitted to the m/ folder (/m/processform.php), but now it always submit to the processform.php of the main directory. I have tried action="//m.example.com/processform.php" but no luck.
Anyone know kow to solve it? Thanks!
Update:
if the method of the form is get instead of post, the form will be submitted correctly (to /m/processform.php)
Actually your rules are skipping POST requests from all rewrite rules. You can tweak the rules to skip POST from external redirects and keep internal rewrites active/enabled for POST like this:
# Redirect external .php requests to extensionless url
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1%2 [R=302,L,NE]
#mobile
RewriteCond %{HTTP_HOST} ^m\.example\.com$ [NC]
RewriteRule ^((?!m/).*)$ m/$1 [L,NC]
# Resolve .php file for extension-less php urls
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
PS: I have also simplified your 2nd rule.
It's possible the first redirect is interferring with the POST request, try changing the request regex to:
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\s/+(.*?/)?(?:index)?(.*?)\.php[\s?] [NC]
I have form on home page index.php which passes variables to page search.php after submission url looks like
justdlal.com/search/Computer-Hardware/Delhi
In the same page i have same form with two inputs city and keyword but after submitting it must go to url like
justdlal.com/search/laptop/Delhi
but instead it is appending search query to current url like
justdlal.com/search/Computer-Hardware/search.php?keyword=laptop&city=Delhi
My htaccess code
RewriteEngine on
RewriteBase /
RewriteRule "^(search)/([^+]*)\++([^+]*\+.*)$" /$1/$2-$3 [L,NC]
RewriteRule "^(search)/([^+]*)\+([^+]*)$" /$1/$2-$3 [L,R=301,NE,NC]
RewriteCond %{THE_REQUEST} \s/+search\.php\?keyword=([^&]+)&city=([^\s&]+) [NC]
RewriteRule ^ /search/%1/%2? [R=301,L,NE]
RewriteRule ^search/([\w-]+)/([\w-]+)/?$ /search.php?keyword=$1&city=$2 [L,QSA]
Try these rules:
RewriteEngine on
RewriteBase /
RewriteRule "^(search)/([^+]*)\++([^+]*\+.*)$" /$1/$2-$3 [L,NC]
RewriteRule "^(search)/([^+]*)\+([^+]*)$" /$1/$2-$3 [L,R=301,NE,NC]
RewriteCond %{THE_REQUEST} /search\.php\?keyword=([^&]+)&city=([^\s&]+) [NC]
RewriteRule ^ /search/%1/%2? [R=301,L,NE]
RewriteRule ^search/([\w-]+)/([\w-]+)/?$ /search.php?keyword=$1&city=$2 [L,QSA]
I've built a site using CMS Made Simple. I have to point the host URL for everything EXCEPT the admin page and the contact forms. I was able to successfully do this with mod_rewrite to the config.php and changing up the .htaccess, but now my contact forms are no longer working (one in the footer and one on the contact page). Here is what my .htaccess file looks like:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^energyfa.ipower.com$ [NC]
RewriteCond %{REQUEST_URI} !^/ai/admin/
RewriteRule ^(.*)$ http://accimpress.com/$1 [R=301,L]
# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
# except for form POSTS
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteCond %{REQUEST_METHOD} !^POST$
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]
# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
Is there a reason my POST exception might not be working? Any suggestions will be much obliged. The website is: http://energyfa.ipower.com/ai/
Thanks,
Cory
try changing your .htaccess from
# .htaccess for CMS made simple
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteCond %{REQUEST_METHOD} !POST$
RewriteRule ^(.*) %{REQUEST_URI}/ [NE,R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
# EOF
to
# .htaccess for CMS made simple
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !$ <--- to put the "/" ---->
RewriteCond %{REQUEST_URI} !\.
RewriteCond %{REQUEST_METHOD} !POST$
RewriteRule ^(.*) %{REQUEST_URI} [NE,R=301,L] <--- to put the "/" after } ---->
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
# EOF
it work for us
I see that the action on your form is set to http://energyfa.ipower.com/ai/contact-us/. What I believe will happen is that the POST will go to that URL. You will hit your first RewriteRule and get redirected to the contact form again, but since it's a browser redirect, it will probably just be a GET, so your POST content never makes it to your script.
Try changing the form action to http://accimpress.com/contact-us/ and see what happens.
It looks like CMS Made Simple doesn't support their Form Builder module once you've redirected your URL with Pretty URLs, so my solution for now was using Send This File, like so:
http://accimpress.com/upload/
But thanks for your suggestions Andrew!