I have created my website using kohana framework and hosted in godaddy. I'm getting 404 page not found error in all links except home page. I have attached .htaccess file here. Kindly provide any ideas regarding this isuse.
# Turn on URL rewriting
RewriteBase /
RewriteEngine On
# Installation directory
#RewriteBase /kohana/
# Protect application and system files from being viewed
RewriteRule ^(application|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]
RewriteRule ^(.*)$ index.php?/$0 [L]
Make sure that .htaccess is in the same directory as all .php files are. /public_html/ or a folder like this.
Working Example
RewriteEngine On
//Optional: Redirect www to non www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
//Optional: Redirect http:// to https://
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
//Edit the URL (Without parameter)
RewriteRule ^login/?$ login.php [QSA]
RewriteRule ^logout/?$ logout.php [QSA]
//Edit the URL (With parameter)
RewriteRule ^user/edit/([0-9]*)/?$ user_edit.php?user_id=$1 [QSA]
If you are hosting on GoDaddy you usually don't need to make a .htaccess for the index.php file.
It happend to me once, i donĀ“t know if it will be the same problem for you but i know that some hosting servers work using case sensitive urls
Example:
if your file has this name= "Login.php"
and if you try to acces to it like this= "login.php" it will not work and that is also applied to the name of folders.
It looks like you got a question mark in your last line that doesn't belong there, it should be:
RewriteRule ^(.*)$ index.php/$0 [L]
Or else try:
RewriteRule .* index.php/$0 [PT]
Related
I search for this but no one solution worked for me.
I already tried many different "solutions" from here, but none of them worked.
I installed WordPress in main root directory of my domain like this example.com/index.php
So I have a .htaccess for WordPress at the root directory of example.com:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
after that, I install the other PHP script in sub-directory of the main domain like this example.com/app/index.php
The .htaccess for PHP script at the sub-directory of example.com/app/index.php :
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
RewriteEngine On
RewriteBase /
# RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
# RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^search/(.+)$ /search.php?q=$1
RewriteRule ^search/([^/]*?)/page/([^/]*?)/$ /search.php?q=$1&token=$2
RewriteRule ^search/([^/]*?)/$ /search.php?q=$1
RewriteRule ^download/([^/]*?)/page/([^/]*?)/$ /search.php?q=$1&token=$2
RewriteRule ^download/([^/]*?)/$ /search.php?q=$1
RewriteRule ^watch/(.+)$ /watch.php?id=$1 [L]
RewriteRule ^home/(.+)$ /index.php?q=&page=$1 [L]
RewriteRule ^(cache/|submit\.php|head\.php|head_mobile\.php|foot\.php|foot_mobile\.php|includes\.php|config\.php) - [F,L,NC]
RewriteRule ^sitemap.xml$ /sitemap.php [L]
RewriteRule ^dmca$ /dmca.php
RewriteRule ^privacy$ /privacy.php
RewriteRule ^contact$ /contact.php
Now my PHP script is not working correctly and all files including CSS, JS, images are not accessible inside sub-directory where PHP script is installed.
I want The URLs should be like these:
https://example.com/app/watch/wVS-hHZsAIg
https://example.com/app/contact-us
https://example.com/app/dmca
https://example.com/app/css/style.css
But all the above URLs not working and Also it redirect to WordPress installation page and give 404 error like these:
https://example.com/watch/wVS-hHZsAIg
https://example.com/contact-us
https://example.com/dmca
https://example.com/css/style.css
MY CSS, JS and other relative resources aren't working. this the issue.
And .htaccess is blocking CSS, javascript, and images from getting access by example.com/app/index.php
RewriteRule ^watch/(.+)$ /watch.php?id=$1 [L]
All your rewrites (such as the one above) are rewriting the URL to the document root, where WordPress is installed. So, a request for /app/watch/wVS-hHZsAIg is being rewritten to /watch.php?id=wVS-hHZsAIg (by the above directive), which I assume does not exist, so it will be routed through WordPress, resulting in a 404.
For this .htaccess file to work in the /app subdirectory, you need to remove the slash prefix from all the substitution strings. For example, the above directive should read:
RewriteRule ^watch/(.+) watch.php?id=$1 [L]
(The trailing $ on the RewriteRule pattern is superfluous.)
https://example.com/app/contact-us
The directives you posted look for contact, not contact-us - so this may be unrelated to the above.
https://example.com/app/css/style.css
Again, this is not related to the above. And is probably caused by incorrect URL paths in your HTML. If you are referencing your CSS with a root-relative URL of the form /css/style.css then this is not going to work. You need to either make the URL-path relative (ie. remove the slash prefix, as for the mod_rewrite directives in .htaccess), or include the full URL-path in the link (preferable). (This is the opposite of what #starkeen referenced in comments.)
See also, this related question on the Webmasters statck:
https://webmasters.stackexchange.com/questions/86450/htaccess-rewrite-url-leads-to-missing-css
I currently have an .htaccess file to rewrite index.php out of all of the base URL's, example example.com/index.php/home -> example.com/home
The .htacces file is as follows in the root of my public_html folder:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|adminer|resources|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
As far as I know, this rewrites any /URL that isn't images, css, resources, etc.. to point toward index.php.
I am now trying to add to my .htaccess a rule to rewrite example.com/forums -> fourms.example.com.
With the current rules in place, I receive a 500 - Internal Server Error when I try to visit forums.example.com. I have also tried the following to no avail:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|adminer|resources|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_URI} ^/forums(.*)
RewriteRule ^forums(.*)$ http://forums.example.com$1 [R=301,L]
How do I change these rules to allow the redirection of index.php and rewrite example.com/fourms to fourms.example.com?
And for the second time today, I have found the answer moments after posting a question:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|resources|forums|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_URI} ^/forums(.*)
RewriteRule ^forums(.*)$ http://forums.example.com$1 [R=301,L]
I had to exclude /forums from the first rewrite, and add in the second rewrite.
I would like to find a RewriteRule that does this :
mysite.net/jqMAS/ or mysite.net/jqMAS => mysite.net/index.php?id=jqMAS
I used such a .htaccess file :
RewriteEngine On
RewriteRule ^(.*) index.php?id=$1
But unfortunately, it doesn't work (maybe mysite.net/index.php is itself redirected to mysite.net/index.php?index.php, etc. ?) : calling mysite.net/jqMAS produces a 500 Internal Server Error.
What RewriteRule should we use to do such URL shortening ?
Here is what the index.php page (I didn't mention the headers) looks like :
<body>
Bonjour <?php echo $_GET['id']; ?>
</body>
Try the following your .htaccess file, as it is the setup successfully used on my own website.
# Enable the rewriting engine.
RewriteEngine On
# Change requests for a shorter URL
# Requires one or more characters to follow the domain name to be redirected
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?id=$1 [L]
There are 2 htaccess files:
Keep your htaccess file within application folder as:
Deny from all.
and paste following code to your htaccess file outside the application folder:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
It is working perfect for me.
You need RewriteCond to stop rewriting for real files and directories:
RewriteEngine On
# if request is not for a directory
RewriteCond %{REQUEST_FILENAME} !-d
# if request is not for a file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?id=$1 [L,QSA]
I have one .htaccess file in the public_html folder of my server that lets me keep my primary domain in a subfolder:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?mrmikeanderson.com$
RewriteCond %{REQUEST_URI} !^/mrmikeanderson/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mrmikeanderson/$1
RewriteCond %{HTTP_HOST} ^(www.)?mrmikeanderson.com$
RewriteRule ^(/)?$ mrmikeanderson/index.php [L]
In that subfolder is another .htaccess with more rewrites to turn urls ending with things like /index.php?page=about into just /about:
RewriteEngine On
RewriteRule ^$ index.php?page=home
RewriteRule portfolio index.php?page=portfolio
RewriteRule resume index.php?page=resume
RewriteRule about index.php?page=about
RewriteRule contact index.php?page=contact
The last four pages work, but my rewrite for just the domain name (\^$) is broken. Everything works on my local MAMP server, but the first .htaccess file is not present there, so I'm thinking that the two are conflicting. Any web dev champs able to see what's going wrong?
I'm assuming you have a /mrmikeanderson/ folder where the 2nd htaccess file is. The reason why the
RewriteRule ^$ index.php?page=home isn't being applied is because you are redirecting the / request to mrmikeanderson/index.php. So either change this rule:
RewriteRule ^(/)?$ mrmikeanderson/index.php [L]
to
RewriteRule ^(/)?$ mrmikeanderson/index.php?page=home [L]
or change this rule in the other htaccess file:
RewriteRule ^$ index.php?page=home
to
RewriteRule ^(index.php)$ index.php?page=home
Or you can change your index.php file to assume the variable page is home by default.
Try commenting out:
RewriteRule ^(.*)$ /mrmikeanderson/$1
It looks like the regex ^(.*)$ will match anything including blank strings, which would conflict with RewriteRule ^$ index.php?page=home
Edit:
Try using ([A-Za-z0-9]+) in place of the ^(.*)$ which should give you:
RewriteRule ^([A-Za-z0-9]+)$ /mrmikeanderson/$1
You can always set up a rewrite log to see what's going on http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritelog
I have a setup that sets variables for the index page, but it also does the same for directories and I don't want it to do that. Here's my .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(login|images|favicon\.ico|home|about|sitemap|contactus|termsandconditions|privacypolicy|signup|search|careers|error|css|js) [NC]
RewriteRule ^([a-zA-Z0-9]+)$ index.php?name=$1
RewriteRule ^([a-zA-Z]+)/$ index.php?name=$1
RewriteRule ^([a-zA-Z]+)/([a-zA-Z0-9_]+)$ index.php?name=$1&page=$2
RewriteRule ^([a-zA-Z]+)/([a-zA-Z0-9_]+)/$ index.php?name=$1&page=$2
RewriteRule ^php/$ error/
Now, with this setup, if I type in mysite.com/login it will redirect to the index.php page and set login as the name variable. How do I make it to where it ignores the directories? This is frustrating me and I've looked through this site for over an hour for an answer and can't find a similar question (I might suck at that too, though. haha!).
Also, if you look at the last RewriteRule, you can see that I'm trying to redirect any attempt to access my php/ folder to my error/ folder. This is also not working.
RewriteCond only applies to the immediately following RewriteRule. Also, you can combine lines 3&4, and 5&6 respectively, by using /? on the end, which makes the / optional (regex).
Your file could be similar to this:
RewriteEngine On
#the following line will not rewrite to anything because of "-", & stop rewiting with [L]
RewriteRule ^(login|images|favicon\.ico|home|about|sitemap|contactus|termsandconditions|privacypolicy|signup|search|careers|error|css|js)/?(.*)$ - [L,NC]
RewriteRule ^php/?(.*)$ error/ [L,NC]
RewriteRule ^([^/]+)/?$ index.php?name=$1 [L]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?name=$1&page=$2 [L]
You may be interested in the Apache Mod_Rewrite Documentation.
RewriteCond %{REQUEST_URI} !^/(login|images|favicon\.ico|home|about|sitemap|contactus|termsandconditions|privacypolicy|signup|search|careers|error|css|js) [NC] !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
to either not execute the rule on a directory or a file
More info on the mod_rewrite documentation pages, search for CondPattern