Wordpress Seo features - apache

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>

Related

.htaccess multiple rewrite rules on multiple php files not working

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]

Annoying Silex subdirectory .htaccess issue

I'm working on a few projects using Silex and on none of them can I get the .htaccess file working. The current directory structure is http://localhost/IIV/
The front file in Silex is in http://localhost/IIV/web/index.php
This is what I have currently:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /IIV/
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
RewriteCond %{DOCUMENT_ROOT}/web/$1 -f
RewriteRule ^(.+?)/?$ /web/$1 [L]
RewriteCond %{DOCUMENT_ROOT}/web/$1 !-f
RewriteRule ^(.+?)/?$ /web/index.php [L]
RewriteRule ^(.+?)/?$ /web/index_dev.php [L]
Your RewriteBase is wrong, try this:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /IIV/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>
Also, make sure Apache is configured to load the .htaccess rules as #Maerlyn mentioned above.

htaccess redirect if a specific folder doesnt exists

I am using this in the root htaccess
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php?p=%{REQUEST_URI} [L]
This rewrites http://example.com/notexistsfolder successfully
But i want also to redirect http://example.com/user/notexistsfolder to http://example.com/notexistsfolder
What code should i add to achieve this ?
Here is the code that you need in .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## 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 ^user/(.*)$ $1 [L,NC]
RewriteRule (?!^user/)^(.*)$ index.php?p=$1 [L,NC,QSA]

htaccess rewrite to maintenance page if exists and not IP, else bootstrap

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>

.htaccess RewriteRule trouble

I am guessing this question has been asked many times, but i could not find one that would perhaps give me what I need.
So.. I can access the scripts by the following url's:
http://website.com/index.php/hello/world
http://website.com/hello/world
Both go to index.php which parses the input (hello/world in this example).
this is my .htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?path=$1&%{QUERY_STRING} [L]
</IfModule>
However. When the site is accessed like this:
http://website.com/index.php/hello/world
the RewriteRule outputs something similar to index.php?path=index.php/hello/world
I want to remove that index.php after path= in the RewriteRule
Your .htaccess file should look like this (notice the new rule that checks if index.php is a part of url):
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index.php/(.*)$ index.php?path=$1&%{QUERY_STRING} [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?path=$1&%{QUERY_STRING} [L]
</IfModule>
Try this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Modifying answer from Stackoverflow answer to suit this question
The .htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Redirect user
RewriteCond %{THE_REQUEST} ^.*index.php.*
RewriteRule ^(.*)index.php(.*)$ $1$2 [NC,R=301,L]
# Handle the query to PHP
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?path=$1&%{QUERY_STRING} [L]
</IfModule>