So I have been looking all over for a while, and cannot seem to find a particular solution I am looking for. I have seen many articles showing how to fix problems with wordpress rewrite, but none fix my problem.
I currently have Wordpress Installed in my / Root directory. the .htaccess looks like this.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^manager - [L,NC] <-- I added this from other examples.
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
So from what I can tell this tells wordpress, hey you will handle all the urls, for everything. forever. Seriously. For ever and everywhere :P
So the problem comes when I have a sub directory site.com/manager
Here I would like to build a similar URL capturing method to manage what the user gets to see/access/etc. The line I added to the root .htaccess file (from what I have read) is suppose to tell wordpress, hey don't touch my damn /manager folder.
Wordpress being the sneaky greedy caregiver that it is fails to listen. ill go to test my site.com/manager/test (grabbing test and pulling info from sql with it) and wordpress takes over and throws me to the wordpress 404 page.
my .htaccess in /manager is as follows for refrence, I am thinking I will need to do some rewrite stuffs here too, but for now just trying to prevent wordpress from being over bearing :).
DirectoryIndex index.php
<FilesMatch "\.(php|inc)$">
Order allow,deny
deny from all
</FilesMatch>
<FilesMatch "(index.php|logout.php)$">
Order allow,deny
allow from all
</FilesMatch>
Any ideas, thoughts, comments, concerns would be much appreciated.
Thank you.
SO after digging deeper and looking into this further I found a fix. Not sure it is the BEST solution but its working.
Root (/) .htaccess
#Manager - A customer content manager
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/manager/(.*)$ [OR]
RewriteRule ^.*$ - [L]
</IfModule>
#end Manager
# 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>
# END WordPress
This appears to over ride wordpress like needed.
Manager (/manager) .htaccess
DirectoryIndex index.php
<FilesMatch "\.(php|inc)$">
Order allow,deny
deny from all
</FilesMatch>
<FilesMatch "(index.php|logout.php|install.php)$">
Order allow,deny
allow from all
</FilesMatch>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /manager/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
The top portion isn't required but I added this for file protection/security.
Summary:
I used the %{REQUEST_URI} to selectively remove a sub-folder, to apply this to more sub-folders I would add another
RewriteCond %{REQUEST_URI} ^/manager/(.*)$ [OR]
I then input the information in the sub-directory's .htaccess file for url rewriting. From here I can manipulate the URL converting it into a Array list for further sorting and database calling.
Related
I am trying to implement SEO friendly URLs using .htaccess and PHP.
I have achieved 90% of my goal and struggling with just one use case.
Here is what happing, when I access the following url
http://somesite.com/cms/movies/tarzan
it lands on
my-handler.php?the_url=movies/tarzan
This is perfect and that is what I want because then I manage it myself. The real problem is when I don't provide any slugs, then it lists the directory (means show all files and folders in it)
http://somesite.com/cms/
Can someone please help me fix following .htaccess content, so that even if I don't provide slug it should still be handled by my-handler.php instead of lisiting full directory?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cms/
RewriteCond %{REQUEST_FILENAME} !/(admin|css|fonts|ico|include|js)/
RewriteRule ^my-handler\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /cms/my-handler.php?the_url=$1 [L,QSA]
</IfModule>
Solved
As per #Roman suggestion, I added the following to the above listing and it solved my problem. Plus I do not have to compromise on accessing physical directories RewriteCond %{REQUEST_FILENAME} !-d
DirectoryIndex my-handler.php
At first you have to set the DirectoryIndex to handle every request which points to / with your my-handler.php. This can be done by adding the line to your .htaccess
DirectoryIndex my-handler.php
To disable the directory listing, you have to forbid the listing by adding the following line to your .htaccess
Options -Indexes
Remember that this configuration is per .htaccess and just for the directory you are placing the file in. If you want to make changes for your whole webserver, you can edit the httpd.conf and search for
Options Indexes
and remove the Indexes option.
Documentation
The listing is provided by the mod_autoindex module.
Nice side-fact
If you just want to disable the listing of specific file-types like .env or .php files, you can add the option IndexIgnore *.php to you .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cms/
RewriteCond %{REQUEST_FILENAME} !/(admin|css|fonts|ico|include|js)/
RewriteRule ^my-handler\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css|json|woff|ttf)
RewriteRule ^(.*)$ /cms/my-handler.php?the_url=$1 [L,QSA]
</IfModule>
I have a website that uses Symfony3 and am trying to integrate a wordpress blog under www.website.com/blog.
So what I've done so far is create a blog folder, under the Symfony web folder, which contains the wordpress files.
I've then added a rewrite rule, in the web/ directory's .htaccess file so that when we are under blog/, Symfony's url rewriting won't do anything :
# Passing through the Url rewriting for all blog/ urls
RewriteRule ^blog/(.*)$ blog/$1 [PT]
So far it's good. I can access the admin section and everything but the problem is that when I try to access www.website.com/blog or even www.website.com/blog/index.php I only get the list of files in the folder and not the actual front page.
And here is the .htaccess file from blog/ folder that was created when I launched the wordpress installation script:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /xxx/web/blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /xxx/web/blog/index.php [L]
</IfModule>
# END WordPress
Any ideas why ?
I think that if you have access to the sites-available's configuration file for your site, i.e. /etc/apache2/sites-available/mysite.conf.
And add a <Directory> for your blog with the WordPress rules:
<Directory /var/www/mysite/web/blog>
DirectoryIndex index.php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
</Directory>
Note: I have added DirectoryIndex index.php by myself because my Symfony have a DirectoryIndex app.php or DirectoryIndex disabled.
If you don't have access to your configuration file, probably you need to add the DirectoryIndex index.php to your .httaccess but then your configuration site and the .httaccess of Symfony should allow this directive, e.g., they should contain AllowOverride All or AllowOverride Indexes FileInfo.
I have a successful implementation of htaccess to remove index.php in codeigniter. Which meant that I can access any controller via domain.com/controllername.
However, I realized that with this implementation I cannot access sub-directory within the server via the URL. Please advice if there is a working solution to resolve such issue.
Thank you
The htaccess which I am using now is as follows
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|update\.php|administrator\.php|assets|admin|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
<FilesMatch ".(ico|jpg|jpeg|png|gif)$">
ExpiresActive On
ExpiresDefault "access plus 1 month"
</FilesMatch>
Mark this may be the probable solution to your issue where you are unable to access the sub
folders of the system.
# if a directory or a file exists, use it directly
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php #Here you write the line which will overwrite the index.php and will move the control to your controller.
The comments in the code are itself self speaking.
For more exact answer post your exact htacess you are using.
Hope that helps you.
if your pointing out another site inside your domain aka sub-folder. Edit your .htaccess like this :
RewriteBase /domain.com/sub-folder/
or
RewriteBase /sub-folder/
I am trying to use fuelcms in my arch linux lamp server. But I cant make htaccess to work. My home folder is ytsejam/fuel_cms/..
This is my .htaccess file :
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
<Files .*>
Order deny, allow
Deny From All
</Files>
# Allow asset folders through
RewriteRule ^(fuel/modules/(.+)?/assets/(.+)) - [L]
# Protect application and system files from being viewed
RewriteRule ^(fuel/install/.+|fuel/crons/.+|fuel/data_backup/.+|fuel/codeigniter/.+|fuel/modules/.+|fuel/application/.+|\.git.+) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/$0 [L]
</IfModule>
Options -Indexes
/var/log/httpd/error_logs show that
/home/ytsejam/public_html/fuel_cms/.htaccess: order takes one argument, 'allow,deny', 'deny,allow', or 'mutual-failure'
can anyone help me ?
You have just inserted additional space after the comma
"deny, allow" must be "deny,allow"
The htaccess file below crashed the site with an internal server error (500). This site has the misc.php patch that's discussed here:
Wordpress Bug #11903
Apparently something else is at play here or the patch is not fully addressing the issue. 3 sites went down yesterday. 2 today (so far). All sites have the patch file that's referenced in the bug track link above.
The issue appears to be a currupt htaccess write operation which results in a malformed htaccess file (see code in red below).
AuthName mysite.net
AuthUserFile /home/mysite/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/mysite/public_html/_vti_pvt/service.grp
Options All -Indexes
# BEGIN WordPress
# BEGIN WordPress root
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress root
dule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress root
As a workaround remove write permissions from your .htaccess.