0
votes
RewriteEngine On
RewriteRule ^([^/\.]+)/?$ $1.php  [L,QSA]

this is my link domain.com/new.php

url is rewriting but the page is not running ... it is throwing an error

Not Found

The requested URL /domin.com/new was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Apache Server at domain.com Port 80

4
Did you specify those lines in Virtual Host / Server configuration or in an .htaccess file? - Callidior
yes,I placed .htaccess file in the directory where i am running the code - user3530708
Is this the root-directory of your domain (i.e. your request URI is "/new") or is it nested inside a sub-directory (i.e. your request URI is like "/subdir/new"). In the latter case, you must set RewriteBase appropriately. - Callidior
yes, Actually I tried to run in the subdir but it is not done... it is not even running in my root dir also - user3530708
so /domin.com/new or /domain.com/new ? - castt

4 Answers

0
votes

It could be that apache rewrite is not enabled in your server. Run this through SSH to enable it:

a2enmod rewrite

Then restart Apache Service:

service apache2 restart

If this doesn't help, it could be that your server is not allowing your htaccess file. To solve this, edit this file: /etc/apache2/sites-available/default.

Look for:

    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
            # Uncomment this directive is you want to see apache2's
            # default start page (in /apache2-default) when you go to /
            #RedirectMatch ^/$ /apache2-default/
    </Directory>

Change:

AllowOverride None

To:

AllowOverride All

Then restart Apache again.

Also, I have had this issue once where apache user (www-data) was not given permission on that particular site. Just an extra hint.

Hope this helps!

0
votes

Try like this otherwise you have issue with apache rewrite. Rule added by you is also correct.

RewriteEngine on
RewriteRule ^new?$ new.php [L]
-1
votes

Try this it worked for me add these lines in your .htaccess root directory or copy go to cpanel your domain Public_html folder,enable show hidden files, goto .htaccess file and paste this command lines : Options -MultiViews

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

</IfModule>

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteRule ^(.*)$ http%1://www.%{HTTP_HOST}/$1 [R=301,L]

Then restart your Apache or PHP-FPM (Optional)

-2
votes

Dont forget even if you do perfect

you have to make the link like this

<li><a href="new">new</a></li>

you should remove the .php extension from the link