I'm writing a few RewriteRules, and my most basic rewrite returns a 404 error. Here's my code:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule s/(.*)/(.*)/$ /page.php?s=$2 [NC,L]
RewriteRule ^submit/$ submit.php [R,L]
# Options All -Indexes
<files .htaccess>
order allow,deny
deny from all
</files>
RewriteRule ^submit/$ submit.php [R,L] is where I'm having trouble.
When I visit domain.com/submit/, my server returns a 404 error saying, "The requested URL /submit/ was not found on this server." It's like the server did not even look at my HTACCESS file. The other RewriteRules work perfectly.
Am I missing something?
You may try this:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !page\.php [NC]
RewriteRule ^s/(.*)/(.*)/$ /page.php?s=$2 [NC,L]
RewriteCond %{REQUEST_URI} !submit\.php [NC]
RewriteRule ^submit submit.php [R,L,NC]
That's it according to the information in the question.
Can't guess what's the first rule for as there are no URL examples to determine the pattern to be matched by the regex or the location of the script.
Something similar happens with the second rule because there is no way to confirm where the script (submit.php) is located as, again, there are no URL examples in the question.
Related
I'm trying to rewrite the URL's with params contained looks like: https://mywebsite/FOF/news/page/page1.php?name=petter&country=usa
I think it's not very aesthetic as url and I would like it to look more like this:
https://mywebsite/spiderman
Actually the rewrite work and give me this result
https://mywebsite/spiderman?name=petter&country=usa until https://mywebsite/spiderman
This is my redirected rules
##Enabling FollowSymlinks and disabling MultiViews options here.
Options +FollowSymlinks -MultiViews
##Setting rewrite base to / here.
RewriteBase /
RewriteEngine on
##Rewriting for page1 uri here.
RewriteRule ^page1$ page1.php
##External redirect rules here.
RewriteCond %{THE_REQUEST} \s/FOF/news/page/page1\.php\s [NC]
RewriteRule ^ /customPage? [R=301,L]
##Internal rewrite rules here...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^customPage/?$ FOF/news/page/page1.php [L,NC]
if someone can help me
With your shown samples, attempts; please try following htaccess Rules. Where customPage is the page which you want to redirect on browser(spiderman in your shown question). This is for specific page request as per your shown samples.
Make sure to clear your browser cache before testing your URLs.
##Enabling FollowSymlinks and disabling MultiViews options here.
Options +FollowSymlinks -MultiViews
##Setting rewrite base to / here.
RewriteBase /
RewriteEngine on
##Rewriting for page1 uri here.
RewriteRule ^page1$ page1.php
##External redirect rules here.
RewriteCond %{THE_REQUEST} \s/FOF/news/page/page1\.php\?name=(?:[^&]*)&country=(?:\S+)\s [NC]
RewriteRule ^ /customPage? [R=301,L]
##Internal rewrite rules here...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^customPage/?$ FOF/news/page/page1.php?name=petter&country=usa [L,NC,QSA]
I want to redirect to my contoller - SiteController.php and action actionLanguage. I think my htaccess is OK but can't reach the action. Everything that I am trying to put in the url leads me to admin/site/index and not to admin/site/language in my particular case. My .htaccess :
# prevent directory listings
Options -Indexes
# follow symbolic links
Options FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/admin/gii/?$
RewriteRule . backend/web/index.php?r=gii [L]
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule ^admin(/.+)?$ /backend/web/$1 [L,PT]
RewriteCond %{REQUEST_URI} ^.*$
RewriteRule ^(.*)$ /frontend/web/$1
This line RewriteRule ^admin(/.+)?$ /backend/web/$1 [L,PT] must execute to backend/web/site/language when I type www.website.com/admin/site/languageright ? Or I am in some mistake? It redirects the request to the admin/site/index now. Appreciate every advice! Thank you in advance!
EDIT:
Backend .htaccess:
AddDefaultCharset utf-8
Options FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
RewriteRule ^static - [L]
How can I redirect below in htaccess
url/api/login?status_check=1 -> `url/stack/api/login.php?status_check=1`
url/u/123456789 -> `url/stack/user/show_profile.php?uid=123456789`
Sorry guys I post here because comments dont provide ability of posting codes. If anyone feels offended, I apologize.
I now get my url redirect working on local environment such as http://localhost/api/signup but it displays an error of 404 when I uploaded to the server as http://server.com/api/signup
<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
Options -Indexes
Options -Indexes
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api/signup stack/api/api.signup.php [NC,QSA]
RewriteRule ^api/signin stack/api/api.signin.php [NC,QSA]
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]
Please can somebody take a look at my .htaccess code to help identify what's wrong.
I am trying to amend all example.php, example.html and example.htm URL's to index.php?filename=example.html
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(index\.php) - [L]
RewriteRule ^([^/\.]+).(php|html|htm)$ index.php?filename=$1.html&%{QUERY_STRING} [L]
</IfModule>
When I enter a URL like example.html I'm taken to the default 404 and not index.php
Try:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?filename=$1 [L,QSA]
</IfModule>
I'm not using the apache .hatacces for a while,
But try this one:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{REQUEST_URI} !^.*/(css|img|js)($|/.*$) [NC]
RewriteRule ^(.*)$ /index.php?filename=$1&%{QUERY_STRING} [L]
Basically what you need is to be sure that the URL didn't have already index.php. You accomplish it with RewriteCond.
After you redirect all to index.php passing the filename as a parameter.
You can add more exception to the RewriteCond like on this example, all content with /css, /js, /img will not pass to this rule.
You can check this thread: Using .htaccess to reroute all requests through index.php EXCEPT a certain set of requests also
I wish to have request for http://user1.domain.com :
return the output from http://www.domain.com/site-client/site.php?site=user1
AND user still see the URL 'http://user1.domain.com' in the browser
Right now I have the following .htaccess:
RewriteEngine On
RewriteBase /
# Protect the htaccess file
<Files .htaccess>
Order Allow,Deny
Deny from all
</Files>
# Disable directory browsing
Options All -Indexes
RewriteCond %{HTTP_HOST} !^www.domain.com
RewriteCond %{HTTP_HOST} !^admin.domain.com
RewriteCond %{HTTP_HOST} ([^.]+).domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/site-client/site.php?site=%1 [L]
The successfully calls the http://www.domain.com/site-client/site.php?site=user1 URL, but it shows it to the user.
How can I avoid this?
You need to get rid of the http://www.domain.com part of yor RewriteRule's target. It tells mod_rewrite that you want a 302 redirect. So your rule should look like this:
RewriteCond %{HTTP_HOST} !^www.domain.com
RewriteCond %{HTTP_HOST} !^admin.domain.com
RewriteCond %{HTTP_HOST} ([^.]+).domain.com [NC]
RewriteCond %{REQUEST_URI} !^/site-client/site.php
RewriteRule ^(.*)$ /site-client/site.php?site=%1 [L]
EDIT: You'll also need a check to keep the rule from looping