I have website at the root of the server
In a subfolder called se i have an installation of drupal, so going to
https://websiteUrl/se
launches drupal. I want only one page of drupal to be accessible and that all other tries go (not changing url so internally please) to this drupal accepted page. This aboslute page url is:
/se/?q=node/555 (se/index.php/?q=node/555 should aussi be rewriten as /se/?q=node/555 )
Other urls that should be rewriten are like se/index.php/?q=string )
i'am fighting with my apache conf file and Directory directive to do that.
here is my httpd.conf
<Directory /var/www/se/>
AllowOverride None
RewriteEngine on
RewriteCond %{QUERY_STRING} q=node/[^555] [OR]
RewriteCond %{QUERY_STRING} ^q=([a-z]*)$
RewriteRule ^(.*)$ /se/index.php?q=node/555 [L,R]
</Directory>
which is Ok for url like index.php?q=node/347 but not ok for index.php?q=searchString. All what i tried to do with a condition where i try to exclude the q=node/555 resulted in a infinite loop or inner javascript / css links being rewritten too (--> bad link)
Thanks !
Related
In my /public_html/ I have installed an WordPress site. Now I have installed an laravel application inside /public_html/app/.
Then in /public_html/app/.htaccess I have added:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
In /public_html/app/public/.htaccess I have added:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /app/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
</IfModule>
When I trying to open https://example.com/app/ I've got error 404. When I try to open directly https://example.com/app/public I've got half working site because it is searching for the css/images in https://example.com/.
What is need to be changed in the htaccesss in order to work.
The goal is to have a button on the main WP site and when I click it to load the laravel site.
RewriteBase /app/
You need to remove the RewriteBase directive. This ends up rewriting the request to /app/index.php, when it should be /app/public/index.php. The default is to rewrite to the current directory (the directory that contains the .htaccess file), so the RewriteBase directive is not required here.
(Or, you could set this "correctly" to RewriteBase /app/public - but that is not necessary and would then hardcode this installation to the /app directory.)
I've got half working site because it is searching for the css/images in https://example.com/
It depends on where your images are. If images are located at /app/public/assets/images/myimage.jpg then you should be referencing your images using a root-relative URL (starting with a slash), excluding the public directory, eg. href="/app/assets/images/myimage.jpg".
UPDATE:
is this means that I now have to manually edit all images, links, buttons, etc on the site in order to add /app/... in front of the assets?
Ordinarily, yes. In the same way you have presumably added /app/ before all your internal links to your pages. (?)
Logo for example - <img src="/assets/main/img/logo.png">
However, since you are using a root-relative URL and your Laravel assets are in a known location, then you could workaround this by implementing a rewrite in the root (WordPress) .htaccess file to rewrite your Laravel assets to the correct location (presumably /app/public/...).
However, this does mean that you cannot then have an /assets subdirectory in the root (without implementing additional filesystem checks), nor have a WordPress URL that starts /assets, since it will conflict and won't be accessible.
For example, at the top of the /.htaccess file, before any other WordPress directives you could do something like the following:
# Rewrite Laravel assets to the correct location
RewriteRule ^assets/.+ app/public/$0 [L]
# BEGIN WordPress
:
Where $0 is a backreference that contains the entire URL-path that is matched by the RewriteRule pattern.
Now, any request for /assets/<something> will be internally rewritten to /app/public/assets/<something>. /assets/ itself won't be rewritten.
I am trying to get Subdomains work for my Site using htaccess, For example:
shopping.site.local should lead the user to site.local/shopping-and-fashion keeping the initial subdomain format, means in an internal redirection that the user can't notice.
I have added the following script:
RewriteCond %{HTTP_HOST} ^shopping.site.local$ [OR]
RewriteCond %{HTTP_HOST} ^www.shopping.site.local$
RewriteRule ^(.*)$ http://www.site.local/shopping-and-fashion/$1 [L]
The redirection happens successfully but in an external way, how to hide the redirection to have always the url:
http://shopping.site.local
and the content of:
http://www.site.local/shopping-and-fashion
Did you tried to use [P] instead of [L] ?
The following uses reverse proxying and should give you what you want
<VirtualHost *:80>
ServerName shopping.site.local
ProxyPass / http://www.site.local/shopping-and-fashion/ nocanon
ProxyPassReverse / http://www.site.local/shopping-and-fashion/
</VirtualHost>
You might have to hack some JS and CSS to accommodate for the path changes if the original files are not relative links friendly.
I am currently having an issue using the URL manager and/or the apache mod_rewrite or maybe something else entirely.
With showScriptName set to false, navigating to addresses such as domain.com/login, domain.com/logout, domain.com/site/login are all behaving the same way. It simply shows the main site/index, as if I were to navigate to domain.com/eeofjew9j8jfdedfmewf (jibberish).
Maybe it's an issue with my Yii settings? Here are those (sorry for the sloppiness):
'components'=>array(
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'login'=>'site/login',
'logout'=>'site/logout',
'register'=>'users/register'
),
,...
Here is how I have my .htaccess setup in the www root:
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
I am using a VPS server, so I have root access to make any changes needed to apache. I've checked my phpinfo and mod_rewrite is running and enabled. In my apache config, I have for my www directory:
AllowOverride All
Options Indexes FollowSymLinks MultiViews
Order allow,deny
Allow from all
I've been scratching my head on this issue through 3 different hosts (godaddy, dreamhost, and lithiumhosting) so I'm assuming it's an issue on my end with this. Now that I have a VPS though, I'm hoping I can finally figure out my issue and solve it.
First verify that the server is parsing the .htaccess file. This is simply done by placing random text in the .htaccess file such as
CREATE AN ERROR
If this gives you a server error then the file is being parsed. You may have to move the .htaccess file up a directory to get this to work.
After this is working check to make sure the rewrite module in Apache is on. First check phpinfo and look for the running module. If not you may have to delete the comment (#) character in front of the module.
After the module shows up in phpinfo then see if you can do a basic rewrite to make sure that there are not problems with Apache.
RewriteEngine on
RewriteRule ^ http://google.com/? [L,R]
If that is not working try adding the
Options +SymLinksIfOwnerMatch
to the file
Once you have Apache doing it's part now it is up to yii. This code:
RewriteEngine On
RewriteBase /mybasedirectory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]
adds the rewrite base option which may be necessary if you do not have the files in the document root such as htdocs
finally if that does not solve the problem then limit your rule to a simple rule such as
'contact'=>'site/contact',
and see if at least redirects to where you think it should. Of course you may have to check the basic rules of .htaccess again to make sure that overide is allowed and there isn't an errant .htaccess in a subdirectory. I hope that helps. I finally got mine working.
What happens if you delete these lines!
enter code here
# otherwise forward it to index.php
RewriteRule . index.php
if you add this code see if it works
'<action:(login|logout|register|contact)>' => 'site/<action>',
my website (thedutchtilt.com) employs AJAX.
Now I know that whenever Google tries to crawl a page, e.g. #!stories/component_74511, it will turn that url into thedutchtilt.com/?_escaped_fragment_=stories/component_74511 .
My question is, how do I format a htaccess redirect so that the aforementioned site will map to the other one?
I've tried
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=stories/component_74511
RewriteRule ^$ http://www.thedutchtilt.com/full.html? [R=302,L]
but trying this just gives http://thedutchtilt.com/?_escaped_fragment_=stories/component_74511, which is my homepage.
I'm really confused now, and nothing seems to be working (sigh).
Kartik
Current .htaccess:
RewriteEngine on
RewriteOptions inherit
# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
RedirectMatch ^/$ /index.html
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=stories/component_74511
RewriteRule ^$ thedutchtilt.com/full.html? [R=302,L]
Thanks for providing .htaccess code. Problem is your this RedirectMatch line:
RedirectMatch ^/$ /index.html
Comment it out and try again. index.html should be loaded as default using this DirectoryIndex directive:
DirectoryIndex index.html
This is supposed to take any uri and send it as part of a query string to a script that will handle it.
RewriteEngine On
RewriteCond %{REQUEST_URI} !(css.php|gif|jpe?g|png|css|js|json|xml|ico)$
RewriteRule ^(.*)(/)?$ index.php?where=$1 [QSA,L]
I'm asking because it works on some servers and not on others. On some it just disregards the whole thing as if url rewriting is off, and on others it reports a bad request whenever .htaccess with the above content is uploaded.
BTH I would change this rule a bit:
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(css.php|gif|jpe?g|png|css|js|json|xml|ico)$
RewriteRule ^(.*)/?$ index.php?where=$1 [QSA,L]
Added \. into RewriteCond pattern to ensure that it only works for files with such EXTENSIONS (otherwise pattern will also match files that have that text at the end i.e. /something/mygif <> /something/my.gif).
Replaced (/) by / in RewriteRule pattern -- it makes no difference in functionality but a bit lighter on resources.
Back to main topic:
If it "disregards the whole thing as if url rewriting is off" then most likely .htaccess files are not supported/enabled (or it should have different name as configured by AccessFileName directive: e.g. AccessFileName ht.access).
To check it try placing some other directives into .htaccess and see if it works (like: ErrorDocument 404 /404.php or DirectoryIndex index.php etc).
If it "reports a bad request whenever .htaccess with the above content is uploaded" then most likely these directives are not allowed to be placed in .htaccess (requires AllowOverride All or at least AllowOverride FileInfo; see docs) or mod_rewrite is not enabled.
Check Apache's error log -- it should have entries mentioning this moment.