my apache error log is full of this, I don't know what is wrong. This is my .htaccess file. Can somebody help me?
RewriteEngine on
# check that the request url is neither a file nor a directory
RewriteRule ^panel/?$ panel/ [NC,L]
RewriteRule ^([A-Za-z0-9-]+)/?$ app.php?slug=$1 [NC,L]
RewriteRule ^([A-Za-z0-9-]+)/index/([A-Za-z0-9-]+)/?$ app.php?slug=$1&index=$2 [NC,L]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule \.(gif|jpg|png|bmp) /images/default.jpg [NC,L]
and I have another subdomain who redirects to this. And htaccess:
RewriteEngine on
RewriteRule ^(.*)$ http://ro.sughy.com/$1 [R=301,L]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule \.(gif|jpg|png|bmp) /images/default.jpg [NC,L]
Related
RewriteEngine On
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.elancemart\.com [NC]
RewriteRule (.*) https://elancemart.com/$1 [L,R=301]
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^services/([a-zA-Z0-9-]+) service_details.php?slug=$1 [NC,L]
RewriteRule ^category/([a-zA-Z-]+) category.php?catSlug=$1 [NC,L]
RewriteRule ^blog/([0-9]+)/([a-zA-Z0-9-]+) blog/article.php?id=$1&&slug=$2 [NC,L]
RewriteRule ^verify/([a-zA-Z0-9-]+) verify.php?verify=$1 [NC,L]
RewriteRule ^services services.php
RewriteRule ^services/page/([\d])$ /services.php?page=$1 [NC,L,QSA]
RewriteRule ^funds add-funds.php [NC,L]
RewriteRule ^sitemap\.xml/?$ sitemap.php
RewriteRule ^article-sitemap\.xml/?$ article-sitemap.php
ErrorDocument 404 /index.php
I am getting 404 error when hitting services/page/([\d+])$ /services.php?page=$1
The file exists, though When I change the rewrite rule to service/page/([\d+])$ it is working fine, I need services in the URL, not service.
With your shown samples, please try following htaccess rules in your htaccess file. I have put 3 of services rules one after another to make it easy looking.
Also make sure your htaccess file is present along side with servcies.php file.
Please make sure to clear your browser cache before testing your URLs.
RewriteEngine On
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.elancemart\.com [NC]
RewriteRule ^(.*)/?$ https://elancemart.com/$1 [L,R=301]
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)/?$ $1.php [L]
RewriteRule ^services/(\w+)/?$ service_details.php?slug=$1 [NC,L]
RewriteRule ^services/?$ services.php [NC,L]
RewriteRule ^services/page/(\d+)/?$ services.php?page=$1 [NC,L,QSA]
RewriteRule ^category/([a-zA-Z-]+)/?$ category.php?catSlug=$1 [NC,L]
RewriteRule ^blog/([0-9]+)/(\w+)/?$ blog/article.php?id=$1&&slug=$2 [NC,L]
RewriteRule ^verify/(\w+)/?$ verify.php?verify=$1 [NC,L]
RewriteRule ^funds/?$ add-funds.php [NC,L]
RewriteRule ^sitemap.xml/?$ sitemap.php [NC,L]
RewriteRule ^article-sitemap.xml/?$ article-sitemap.php [NC,L]
ErrorDocument 404 /index.php
I´ve made some RewriteRules in my .htaccess and they all work if I call my Website from the Domain/URL of my server.
Now I wanted to point an external Domain to my subfolder on my server where my Website is located, but all RewriteRules aren´t working anymore. When I call the php-files everything is alright, but when I call my "beautiful" links, I wanted to create, then only error 404 is shown.
This is currently my .htaccess file:
ErrorDocument 401 /401.php
ErrorDocument 404 /404.php
RewriteEngine On
#redirect www request to the base domain
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#ignore existing files and directories
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule .* - [L]
# Check if query string exists
RewriteCond %{QUERY_STRING} ^$
# Check that the request is not for an existing file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^spielplan$ spielplan.php [NC,L]
RewriteRule ^rangliste$ rangliste.php [NC,L]
RewriteRule ^alletipps$ allbets.php [NC,L]
RewriteRule ^benutzerseite$ userpage.php [NC,L]
RewriteRule ^einstellungen$ usersettings.php [NC,L]
RewriteRule ^spiel/([0-9]+)/?$ spiel.php?id=$1 [NC,L]
RewriteRule ^user/([A-Za-z0-9-]+)/?$ user.php?name=$1 [NC,L]
RewriteRule ^([A-Za-z0-9-]+)/?$ $1.php [NC,L]
I found a solution.
Because I tried to map my domain to a subfolder, this subfolder needs to work like an DocumentRoot and not like a subfolder.
So I needed to add:
RewriteBase /
in my .htaccess
I've been working on a website and have made some changes to my .htaccess file recently. Whenever I went to localhost/company it redirected me correctly, but now whenever I go to localhost/company it redirects me to http://localhost/company.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php.php// with a 404 page error, so obviously that page doesn't exist. It redirects me to the wrong URL.
I am pretty sure the issue comes from my .htaccess file, I've rolled back .htaccess from 3 months ago and this issue still occurs.
Here's my .htaccess:
RewriteEngine On
RewriteRule ^config\.php - [R=404,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
ErrorDocument 404 /404.php
RewriteRule ^i(/.*)?/company /company [L,NC]
# disable directory browsing
Options All -Indexes
<FilesMatch "\.(htaccess|htpasswd|ini|phps|fla|psd|log|sh|svn|7z|zip|rar|gz|tar)$">
Order Allow,Deny
Deny from all
</FilesMatch>
I hope you can help me! Thanks!
As mentioned in comments, you will likely get this redirect loop if contact.php does not exist.
RewriteEngine On
RewriteRule ^config\.php - [R=404,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
Try changing these first few lines to (assuming this .htaccess file is in the document root):
RewriteEngine On
RewriteRule ^config\.php - [R=404,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^/]+)/$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1/$2.php -f
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php [L]
This simply checks first that the file would exist, before rewriting. I've also added the L (last) to both these directives - I can't see that any later rules depend on these?
Am trying to do an IP and a URL canonicalization on my .htaccess for my website(www.mydomain.com.ng) and IP(http://173.254.30.129/) i did the below code but it did not work.
RewriteEngine On
Options -multiviews
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{HTTP_HOST} !^www.mydomain.com.ng$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com.ng/$1 [L,R=301]
RewriteRule ^index$ index.php [NC,L]
I did the above code on my .htaccess and i visit my URL(mydomain.com.ng) it did not redirect to this (www.mydomain.com.ng).
RewriteEngine On
Options -multiviews
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{HTTP_HOST} ^173\.254\.30\.129
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]
RewriteRule ^index$ index.php [NC,L]
I did the above code on my .htaccess i visit this IP(http://173.254.30.129/) it does not redirect to this (www.mydomain.com.ng).
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [F,L]
also i want to do the above code on my .htaccess but do not know want to test for if it work.
Please help me with this three issue with am trying to achieve in my .htaccess Thank you.
not sure if you still have this issue seeing as this question is over 6 months old, but here are the codes that work for me:
Redirecting the url:
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
Redirecting the IP address:
RewriteCond %{HTTP_HOST} ^XXX\.XXX\.XXX\.XXX
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]
Your last piece of code is to avoid attacks by botnet scripts that automatically look for vulnerabilities in your software.
They are sometimes identified as User-Agent libwww-perl, and that's why you are supposed to disallow access from User-agent Libwww-perl.
As to how to test that I'm not sure of unfortunately.
I have the following .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain.com
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^mykeyword$ news.php [L,QSA,NC]
However, when I open the news.php, the url is still the same, that is www.mydomain.com/news.php instead of www.mydomain.com/mykeyword
I make the following test:
RewriteEngine on
RewriteRule ^test\.html$ test.php [L]
I upload 2 files on my server, test.html and test.php and after I type www.mydomain.com/test.html, my php page was displayed, so that mean that I have no problem with my settings. What on earth I am doing wrong???
Any help will be deeply appreciated.
Regards,Zoran
Change your .htaccess to this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(mydomain\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+news\.php [NC]
RewriteRule ^ mykeyword [R=301,L]
RewriteRule ^mykeyword/?$ news.php [L,NC]
The rewrite rule translates from the URL supplied by the user to the URL seen by the server. Try browsing to www.mydomain.com/mykeyword - you should see the page news.php.