I'm new on .htaccess and rewrite rules. So if my question is not relevant, please forgive me.
I have below Rewrite rule;
RewriteRule ^\yazarlar$ /writer-list.php [L]
I'm trying to achieve if someone hit url http://example.com/yazarlar or http://example.com/yazarlar/ they should see http://example.com/writer-list.php file. But it's not working.
Am i missing something?
FULL .htaccess
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond ${REQUEST_URI} ^.+$
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf|xml)$ [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
## If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
## If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
## If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
## don't do anything
RewriteRule ^ - [L]
RewriteRule ^haber/([^/]+)-([^/]+)/?$ article.php?link=$1&i=$2 [L]
RewriteRule ^([^/]+)/([0-9]?)?$ /article-list.php?link=$1&page=$2 [L]
RewriteRule ^([^/]+)?$ /article-list.php?link=$1 [L]
RewriteRule ^\yazarlar$ /writer-list.php [L]
No need to escape the \y and remove redundant rules:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} \.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf|xml)$ [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
RewriteRule ^yazarlar/?$ writer-list.php [L,NC]
RewriteRule ^haber/([^/]+)-([^/]+)/?$ article.php?link=$1&i=$2 [L,QSA,NC]
RewriteRule ^([^/]+)/([0-9]+)/?$ article-list.php?link=$1&page=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ article-list.php?link=$1 [L,QSA]
Related
I have the following .htaccess in parent directory :
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} login.php [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
Then i have another .htaccess in a sub directory :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /mobile/new_mobile/index.html [NC,L]
Each of them separately does its job and works fine, but i want to use them both combined but cant seem to figure out how, i tried both :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /mobile/new_mobile/index.html [NC,L]
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} login.php [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
and
RewriteEngine on
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} login.php [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /mobile/new_mobile/index.html [NC,L]
You can use this combined .htaccess in site root .htaccess (parent directory):
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} /login\.php [NC]
RewriteRule ^ https://%{HTTP_HOST}/%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^sub/(.*) /mobile/new_mobile/index.html [NC,L]
currently, I've used this code in my htaccess
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Allow any files or directories that exist to be displayed directly
RewriteCond ${REQUEST_URI} ^.+$
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf|xml)$ [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
Options -Indexes
This will hide my directory and let me view my file, but how to put together redirect (code below) into above code?
RewriteCond %{HTTP_HOST} !^www\.nextdomain\.com$ [NC]
RewriteRule ^(.*)$ https://www.nextdomain.com/$1 [L,R=301]
Okay here the answers after get guide from #Nic3500
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L]
RewriteCond %{HTTP_HOST} !^www\.nextdomain\.com$ [NC]
RewriteRule ^(.*)$ https://www.nextdomain.com/$1 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond ${REQUEST_URI} ^.+$
RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf|xml)$ [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
I'm not sure if mod rewrite should be used here:
I'd like to rewrite one url:
www.baseurl.com/url-with-hyphens
to:
www.baseurl.com/controller/method
This is a codeigniter application, here are my current rules:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
I have tried:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
RewriteRule ^.registration/available/2 /u-s-course-schedules/
Thanks
How would I rewrite all requests to maintenance.php, if it exists, except images, and except an IP white list.
If maintenance.php does not exist it should rewrite to a bootstrap (index.php) if the requested file does not exist.
If maintenance.php does exist and the IP is in the white list, then it should rewrite to a bootstrap (index.php) if the requested file does not exist.
I have tried many variations of the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f
RewriteCond %{REQUEST_FILENAME} !\.(jpg|png|gif)$
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123$
RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111$
RewriteRule . maintenance.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
</IfModule>
I would do it in reverse. Rewrite to the bootstrap if the maintenance page doesn't exist or the IP is valid.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/maintenance.php !-f [OR]
RewriteCond %{REMOTE_ADDR} ^123\.123\.123\.123$ [OR]
RewriteCond %{REMOTE_ADDR} ^111\.111\.111\.111$
RewriteRule . index.php [L]
RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f
RewriteCond %{REQUEST_FILENAME} !\.(jpg|png|gif)$
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123$ [OR]
RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111$
RewriteRule . maintenance.php [L]
So, basically it will run index.php IF:
(Not a file)
&& (Not a dir)
&& (
(Maintenance Doesn't Exist)
|| (Remote Addr == 123.123.123.123)
|| (Remote Addr == 111.111.111)
)
We could expand this out using propositional logic, but why bother...
This is what I ended up using
I hope it help any future visitors:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/maintenance.php !-f [OR]
RewriteCond %{HTTP:X-Forwarded-For} ^(x\.x\.x\.x|y\.y\.y\.y|z\.z\.z\.z)$ [OR]
RewriteRule . index.php [L]
RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f
RewriteCond %{REQUEST_FILENAME} !\.(jpg|png|gif)$
RewriteCond %{HTTP:X-Forwarded-For} !^(x\.x\.x\.x|y\.y\.y\.y|z\.z\.z\.z)$
RewriteRule . maintenance.php [L]
</IfModule>
Also #ircmaxell gets the tick because he helped me come to this solution.
Try enclosing your IP addresses within brackets in the same RewriteCond:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f
RewriteCond %{REQUEST_FILENAME} !\.(jpg|png|gif)$
RewriteCond %{REMOTE_ADDR} !^(123\.123\.123\.123|111\.111\.111\.111)$
RewriteRule . maintenance.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
</IfModule>
I am working with wordpress in apache.Now am in very big trouble.I need to rewrite my url.
I am trying by this code for .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /shopboxcms/
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} gallery\_remote2\.php
RewriteCond %{REQUEST_FILENAME} !main\.php
RewriteRule . - [L]
RewriteRule ^wp-admin\/widgets111\.html$ /wordpress/wp-admin/widgets.php
RewriteRule ^hai$ http://localhost/shopboxcms/index.php?productid=62953
</IfModule>
But by using this .htaccess file when we try to call http://localhost/shopboxcms/hai which shows http://localhost/shopboxcms/?productid=62953 but I need the reverse. How can I solve it?
I got the answer:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} gallery\_remote2\.php
RewriteCond %{REQUEST_FILENAME} !main\.php
RewriteRule . - [L]
RewriteRule ^[A-Za-z-0-9,"'-]+\-([0-9]+)$ demo/index.php?productid=$1
</IfModule>